SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

jollyguy77
Starting Member

4 Posts

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

India
52323 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
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.03 seconds. Powered By: Snitz Forums 2000