Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
why error 'Msg 2627, Level 14, State 1, Line 12 Violation of PRIMARY KEY constraint 'PK_CONTACTROLS_PRIMARYKEY'. Cannot insert duplicate key in object 'dbo.CONTACTROLS'. The duplicate key value is (15, 1). The statement has been terminated.' apperes when i try to update the record with 'IT Support Specialist ' to 'Developer'


SQL
UPDATE CR
SET CR.ROLEIDS = (SELECT
  ROLEID
FROM ROLES
WHERE ROLETITLE = 'Developer')
FROM CONTACTROLS AS CR
INNER JOIN ROLES AS R
  ON CR.ROLEIDS = R.ROLEID
WHERE R.ROLETITLE = 'IT Support Specialist'


What I have tried:

this code was written without aliases but i just added the aliases still not work
Posted
Updated 26-Sep-19 13:38pm

1 solution

That error appears to say that there is a Primary Key (PK) on the table and the update statement would create a second recording matching the PK values
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900