Connecting Tech Pros Worldwide Forums | Help | Site Map

sql server

Newbie
 
Join Date: Aug 2009
Location: Viet Nam
Posts: 12
#1: Oct 7 '09
Hi all,
I have a problem that need to solve: I have a table that is called empVisit.
There was a error when inserting: Violation of PRIMARY KEY constraint 'PK_EmpVisit'. Cannot insert duplicate key in object 'dbo.EmpVisit'.
The statement has been terminated.
PRIMARY KEY is Id field of the table. I need to insert a new record with the same Id value to that table.
So how to solve this problem?
Pls help me, thanks in advance,

--Ha

myusernotyours's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 168
#2: Oct 7 '09

re: sql server


You should start thinking about why you really want to insert the same ID twice. you most probably have a badly designed database and/or program.

Regards,

Alex.
Newbie
 
Join Date: Aug 2009
Location: Viet Nam
Posts: 12
#3: Oct 7 '09

re: sql server


Quote:

Originally Posted by myusernotyours View Post

You should start thinking about why you really want to insert the same ID twice. you most probably have a badly designed database and/or program.

Regards,

Alex.

So, there is no way to solve this problem, right?
myusernotyours's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 168
#4: Oct 7 '09

re: sql server


Quote:

Originally Posted by Ha Nguyen View Post

So, there is no way to solve this problem, right?

Absolutely. There is no way you can possibly solve this huge monster of a problem. Not in 100 years.

Regards,

Alex.
Newbie
 
Join Date: Aug 2009
Location: Viet Nam
Posts: 12
#5: Oct 7 '09

re: sql server


Anyway, thanks for your answer, Alex

Ha
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#6: Oct 7 '09

re: sql server


Quote:

Originally Posted by Ha Nguyen View Post

.. I need to insert a new record with the same Id value to that table.
..

Why do you need to insert a duplicate key?
Do you just want to update the other values instead?
If you do need to have many records with the same value in the key field then your key constraint is not correct and should be removed.
Reply