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 2005 Forums
 Other SQL Server Topics (2005)
 Unable to add primary key
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

npgawade
Starting Member

2 Posts

Posted - 07/15/2012 :  20:12:25  Show Profile  Reply with Quote
Hi,

I am trying to add PK on exsting table having data.

My script:


1.ALTER TABLE dbo.Posting_Zeroes_post_dates ADD [ID] [INT] PRIMARY KEY IDENTITY (1, 1) NOT NULL

Before running this script I am droping the exsisting index on that table . just giving more details.

2.ALTER TABLE dbo.Posting_Zeroes_post_dates DROP CONSTRAINT IX_Posting_Zeroes_post_dates

I am getting error on 1 sql.
Error :
Msg 1505, Level 16, State 1, Line 1
CREATE UNIQUE INDEX terminated because a duplicate key was found for object name 'dbo.Posting_Zeroes_post_dates' and index name 'PK__Posting_Zeroes_p__20285207'. The duplicate key value is (69).
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.
The statement has been terminated.

I have check and could not find duplicate records.

I am restoring data from Prodcution to Test and ran the above sql , i got above error but if i ran the sql again after half an hour it ran sucessfully.


Any help would be appreciated.

Thanks.

RitaBowman
Starting Member

USA
10 Posts

Posted - 07/18/2012 :  08:59:41  Show Profile  Reply with Quote
I believe you need to include the Key Name as shown below:

ALTER TABLE dbo.Posting_Zeroes_post_dates ADD [ID] [INT] PRIMARY KEY (IX_Posting_Zeroes_post_dates) IDENTITY (1, 1) NOT NULL

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