I am consolidating incorrect entries in a table. Specifically for this online shop there are manufacturers and their article numbers. Sometimes manufacturers have been created twice with two different names, such as "VHY" and "Vishay" which should be the same. So I want to consolidate this into one correct manufacturer.
I have the following SQL statement:
/** Old Manufacturer Name **/
DECLARE @old varchar(100) = 'VHY';
/** New Manufacturer Name **/
DECLARE @new varchar(100) = 'VISHAY';
/** Updating the table **/
UPDATE [ESO65].[dbo].[ESO$Manufacturer Item]
SET [Manufacturer Code] = @new
WHERE [Manufacturer Code] = @old
Unfortunately I get the error message:
Violation of PRIMARY KEY constraint 'ESO$Manufacturer Item$0'. Cannot insert duplicate key in object 'dbo.ESO$Manufacturer Item'.
This is because there are duplicate entries where Manufacturer Code = VHY, Manufacturers Item No_= TEST
and Manufacturer Code = Vishay, Manufacturers Item No_= TEST
. So this is the duplicate object violation.
How do I delete all entries for old where there is double entries and then rename the old to new?