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
 General SQL Server Forums
 New to SQL Server Programming
 Primary Key

Author  Topic 

shamasm
Starting Member

11 Posts

Posted - 2011-11-17 : 06:18:45
Msg 2627, Level 14, State 1, Procedure spElOutAdtStatusInsert_net_ls, Line 116
Violation of PRIMARY KEY constraint 'PK_el_out_adt_status_ls'. Cannot insert duplicate key in object 'dbo.el_out_adt_status_ls'. The duplicate key value is (01, 1, 2).
The statement has been terminated.


I am getting this error while I am trying to insert the data in the table el_out_adt_status_ls , but no duplicate data is passed.

Mahajabeen shama m

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-11-17 : 06:37:08
Are you sure? Could be duplicate with data that is already in the table or a duplicate in the data you are inserting.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

shamasm
Starting Member

11 Posts

Posted - 2011-11-17 : 06:41:51
ya i am sure .. Only two records are there.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2011-11-17 : 06:48:03
Delete the records from table and then insert the new records.

PBUH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-11-21 : 03:01:25
quote:
Originally posted by shamasm

ya i am sure .. Only two records are there.



Can you post the table structure, existing data and the INSERT staement that you are using? Also is there a trigger defined on this table that insert some data to other tables?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-21 : 03:08:22
quote:
Originally posted by shamasm

Msg 2627, Level 14, State 1, Procedure spElOutAdtStatusInsert_net_ls, Line 116
Violation of PRIMARY KEY constraint 'PK_el_out_adt_status_ls'. Cannot insert duplicate key in object 'dbo.el_out_adt_status_ls'. The duplicate key value is (01, 1, 2).
The statement has been terminated.


I am getting this error while I am trying to insert the data in the table el_out_adt_status_ls , but no duplicate data is passed.

Mahajabeen shama m


can you add a condition like below to insert statement

INSERT INTO dbo.el_out_adt_status_ls
your select query here
WHERE NOT EXISTS(SELECT 1 FROM dbo.el_out_adt_status_ls
WHERE yourprimarykeycolumn= yourselectcolumncontainingpkvalue)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -