Click here to Skip to main content
14,326,294 members
Rate this:
Please Sign up or sign in to 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'


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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100