我有一张带有主键的表event_id
。我需要将Plant
from更改IM17
为SG18
.
我不想删除这些行(出于历史原因保留)。执行以下 SQL 时出现 PK 违规。
DECLARE @plant CHAR(4)
DECLARE @l_event_id INT
SELECT @plant = 'SG18'
SET @l_event_id = (SELECT MAX(cast(event_id as int)) FROM dbo.event_header)
INSERT INTO dbo.event_header (
event_id, scenario_name, actor_code, method_code,
SAP_plant_code, object_id,serial_no
)
SELECT @l_event_id + 1 , eh.scenario_name, eh.actor_code,
eh.method_code, @plant, eh.object_id, eh.serial_no
FROM dbo.event_header eh
WHERE eh.SAP_plant_code = 'IM17';