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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 To change an existing column to a UNIQUE Column?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

4 Posts

Posted - 03/13/2013 :  12:22:08  Show Profile  Reply with Quote

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.


Very Important crosS Applying yaK Herder

52326 Posts

Posted - 03/13/2013 :  12:39:14  Show Profile  Reply with Quote
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

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000