Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 a unique constraint with more than 1 null

Author  Topic 

sarai
Starting Member

6 Posts

Posted - 2007-03-22 : 14:07:25
I created a unique constraint on a column called Col1 in table Test1 to enforce uniqueness with the exception of NULL. As soon as I add data and try to enter a second record with NULL in Col1, I receive a message that says I've violated the unique constraint. What is the best way to get around this problem? I created trigger on insert/update to check it column violate uniqueness constraint. Is there any other better way to enfore uniqueness on null columns

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-03-22 : 14:23:23
You can do it with an indexed view.

See this example:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=79160


CODO ERGO SUM
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-03-23 : 06:58:27
We used that solution in our application and hated it over time. I've forgotten why, but I think we had trouble with ARITH_ABORT of one of those ANSI-type flag settings.

In the end we wrote a Trigger that checked that the new row was not a duplicate of any existing row (except itself), and just stuck a non-unique index on it (to speed up the Trigger's action)

Kristen
Go to Top of Page
   

- Advertisement -