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
 Transact-SQL (2000)
 To change an existing column to a UNIQUE Column?

Author  Topic 

jollyguy77
Starting Member

4 Posts

Posted - 2013-03-13 : 12:22:08
Hi,

I have a table that has around 5000 records. I have a requirement that i want to change a varchar column to UNIQUE, but the problem is that there are many rows that has empty values in it. If i try to change the column to UNIQUE, i am getting an error that "The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name. The duplicate key value is ()". My requirement is that the Column should have a Unique values in select cases while adding a new rows, sometimes null values can also be present. Is there a way for me to create a UNIQUE for that column. If i create a Trigger will that work out? If so how.

Thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-13 : 12:39:14
you can create unique constraint only after removing current duplicates

However, if you want constraint to be enforced only for newly added records, you can add constraint with NO CHECK option



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -