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.
Author |
Topic |
mrsaif
Starting Member
43 Posts |
Posted - 2006-09-08 : 03:26:20
|
Hi, I have a table Accounts with column userName, currently there is not any uniqu Key contarint on that column. I wnat to add Unique Key contraint on that column. How should i do that?Muhammad Saifullah |
|
eyechart
Master Smack Fu Yak Hacker
3575 Posts |
Posted - 2006-09-08 : 03:42:09
|
try this:ALTER TABLE accounts ADD CONSTRAINT ak_accounts__username UNIQUE (username) that will create a unique key called ak_accounts__username on username column of the accounts table.-ec |
 |
|
mrsaif
Starting Member
43 Posts |
Posted - 2006-09-08 : 03:57:20
|
Thanks, some existing records violates the unique key constraints how to fix those... ? means how to use no check option ??Muhammad Saifullah |
 |
|
eyechart
Master Smack Fu Yak Hacker
3575 Posts |
Posted - 2006-09-08 : 04:02:28
|
quote: Originally posted by mrsaif Thanks, some existing records violates the unique key constraints how to fix those... ? means how to use no check option ??
no, you need to find the duplicates and deal with them first. how to find dupes? good question:SELECT username FROM accountsGROUP BY username HAVING COUNT(*) > 1 -ec |
 |
|
|
|
|