Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

To change an existing column to a UNIQUE Column? Expand / Collapse
Author
Message
Posted Wednesday, March 13, 2013 10:22 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, February 20, 2014 4:04 AM
Points: 9, Visits: 23
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.
Post #1430507
Posted Wednesday, March 13, 2013 10:27 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:55 AM
Points: 13,008, Visits: 12,427
rajagopalanseeth (3/13/2013)
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.


Your definition contradicts what you want to do. You can't have both a unique constraint and duplicate values.

Not quite sure what you mean by unique values in select cases.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1430511
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse