Link to home
Start Free TrialLog in
Avatar of sybe
sybe

asked on

Index, but Field value must be unique or Null

I am working on a database that synchronizes records in a table "person" from another database, but also has records that are not imported. So I created a field in my table which holds the id of the record in the other database, I need to be sure which records correspondences with which record in the other database.

The value of this field should be either be null (no corresponding record in the other database) or unique: there should not be two of the same values. But I can not create a unique index, because then SQL Server complains about several records having value Null.

How can I solve this?

ASKER CERTIFIED SOLUTION
Avatar of Lowfatspread
Lowfatspread
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sybe
sybe

ASKER

I have created a trigger. Thanks. All I wanted to know if there was something like a special unique index that would ignore Null values.
no unfortunately MS SQL Server doesn't allow UNIQUE WHERE NOT NULL Indexes like DB2/UDB