supergirl2008
asked on
how do you update rows and not violate a PK on the table?
i have the following SQL:
UPDATE Products_ProductComponents
SET Products_ProductComponents .Component ID = products_list_ORIG.derived From
FROM Products_ProductComponents
INNER JOIN products_list_ORIG ON products_list_ORIG.Product ID = Products_ProductComponents .Component ID
WHERE products_list_ORIG.derived From <> 0
the updated sets values in the PM that already exist and i get this error:
Violation of PRIMARY KEY constraint 'PK_Products_ProductCompon ents'. Cannot insert duplicate key in object 'dbo.Products_ProductCompo nents'.
how do i get around this?
i am thi nking i can update only records that will not violate the PK
or remove the PK, then delete dups then add PK back.
ideas?
UPDATE Products_ProductComponents
SET Products_ProductComponents
FROM Products_ProductComponents
INNER JOIN products_list_ORIG ON products_list_ORIG.Product
WHERE products_list_ORIG.derived
the updated sets values in the PM that already exist and i get this error:
Violation of PRIMARY KEY constraint 'PK_Products_ProductCompon
how do i get around this?
i am thi nking i can update only records that will not violate the PK
or remove the PK, then delete dups then add PK back.
ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This wouldn't work, you can not add a key if it would violate the key you are adding.