主キーを持つテーブルがありますevent_id
。Plant
をから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';