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 |
|
swathigardas
Posting Yak Master
149 Posts |
Posted - 2008-11-17 : 01:24:27
|
| Hi when i'm trying to create a unique constraint for table TEmployee_Certification.. It is showing the following error Msg 1505, Level 16, State 1, Line 1CREATE UNIQUE INDEX terminated because a duplicate key was found for object name 'dbo.TEmployee_Certification' and index name 'TEmployee_Certification_XU'. The duplicate key value is (343).Msg 1750, Level 16, State 0, Line 1Could not create constraint. See previous errors.The statement has been terminated.This Table already has a primary key.Cant i create one more unique index on itThanks in Advance |
|
|
swathigardas
Posting Yak Master
149 Posts |
Posted - 2008-11-17 : 01:31:09
|
| I'm using this code to create unique constraint ALTER TABLE TEmployee_Certification ADD CONSTRAINT [TEmployee_Certification_XU] UNIQUE(Certificate_ID) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-17 : 01:31:49
|
you can create. no problem. But it seems like column in which you're trying to create unqiue index already contains duplicate value. AS such it will violate constraint thats why its not allowing creation.You can either remove or correct the duplicate values avialable in your table after identifying them using querySELECT yourindexfield FROM Table GROUP BY YourIndexfield HAVING COUNT(*)>1 or create the unique index with option WITH IGNORE_DUP_KEY = ON |
 |
|
|
swathigardas
Posting Yak Master
149 Posts |
Posted - 2008-11-17 : 01:52:14
|
| Hey thanks Vishakh... I've deleted the duplicates and created it |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-17 : 02:08:54
|
Welcome |
 |
|
|
|
|
|