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.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 Unable to add primary key

Author  Topic 

npgawade
Starting Member

2 Posts

Posted - 2012-07-15 : 20:12:25
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

10 Posts

Posted - 2012-07-18 : 08:59:41
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

zohaa3492
Starting Member

1 Post

Posted - 2014-12-18 : 02:57:18
hi ,

i am working on my project .i just need little help from sql server.i installed it and when i start it it appears " connect to server " window. whiask for server name. Plz guys tell me whats the server name i have to enter bacause i have tried all names like pc name ,comouter name....


Plz somebody tell me the solution...


________________________
We are the pioneers in providing [url=http://www.braindumps.com/MCSA.htm]mcsa certification[/url] toefl and [url=http://www.braindumps.com/ITIL.htm]itil dumps[/url] with 100% exam pass [url=http://www.northwood.edu/]northwood[/url] Download our latest passguide gmat and [url=http://www.ku.edu/]www.ku.edu[/url] ccna or pass real exam of [url=http://en.wikipedia.org/wiki/Florida_Memorial_University]Florida Memorial University[/url]
Go to Top of Page

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2014-12-18 : 03:11:49
it is the instance name that you gave when installing sql server on your machine.
click on 'Browse for more' under servers and you must see the instance name under local server-database engine

Javeed Ahmed
https://www.linkedin.com/pub/javeed-ahmed/25/5b/95
Go to Top of Page
   

- Advertisement -