Options

unique index on a table (apart from PK)

a_developera_developer Member Posts: 20
A table has two fields that should be unique (as a pair of values). The table already has a PK. How can I create a key that is unique for those 2 fields. Thi s will remove the headache of writing the trigger that checks if the pair of values already exists in the table.


To put it another way: In a classic RDBMS I would have created a unique composite Index for those two fields that is NOT the PK of the table. what do I do in Navision?

tx

Comments

  • Options
    xrivoxrivo Member Posts: 56
    In Navision the firs key you define (when you are in Design mode on a table go to view keys ) is the primary key ..so you must define your combination of fields to be the first key ///
  • Options
    DenSterDenSter Member Posts: 8,304
    Nope, there is no such thing as a secondary unique key in Navision. Secondary keys in navision are for sorting purposes only (and speed issues on various flowfields and reports and stuff, but those are sorting issues to begin with). I'm sorry to say you will have to write that code :oops:
  • Options
    KowaKowa Member Posts: 918
    edited 2005-06-27
    Also, the PK is always automatically added to the secondary keys to make them unique. It can sometimes be dangerous to add new fields to an existing key. If code was written using the first fields of this key and assuming the PK to be the next , then stepping through the table with the altered key will return unforeseen results. :shock:
    Kai Kowalewski
  • Options
    bostjanlbostjanl Member Posts: 107
    A table has two fields that should be unique (as a pair of values). The table already has a PK. How can I create a key that is unique for those 2 fields. Thi s will remove the headache of writing the trigger that checks if the pair of values already exists in the table.


    To put it another way: In a classic RDBMS I would have created a unique composite Index for those two fields that is NOT the PK of the table. what do I do in Navision?

    tx

    Use trigers (OnValidate or OnModify/OnInsert) and check if yours 2 fields are "unique".


    BostjanL
  • Options
    a_developera_developer Member Posts: 20
    thank you all for your feedback.

    I guess I will have to write the triggers after all :(
Sign In or Register to comment.