Unique Constraint

Fisherman
Fisherman Member Posts: 456
Can anyone tell me how to issue a unique constraint (not a primary key - I have no natural key for a table that I have created, and instead want to use a surrogate). I have set it in SQL for that index (key), but I've discovered that the documentation shows that setting a unique key in SQL for fields other than the primary key may not work as expected...

Answers

  • Waldo
    Waldo Member Posts: 3,412
    Well, actually, you have to do this in code (afaik) ... OnValidate of the field.

    :-k

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • Fisherman
    Fisherman Member Posts: 456
    got it to work.

    re-added my table, and added my primary key. Then I added a key on my columns that I wanted to make unique.

    I then went into SQL Enterprise Manager, found the key that encompassed my fields, and set the index to a unique constraint.

    Works great so far.
  • Waldo
    Waldo Member Posts: 3,412
    What if you re-compile / do some minor changes to the table? Does the unique constraint keep existing, or does the NAV client reset the indexes?

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • Fisherman
    Fisherman Member Posts: 456
    I've recompiled twice since I built the original table, and it hasn't deleted it yet.
  • Waldo
    Waldo Member Posts: 3,412
    OK, nice to know ... thanks!

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog