在我的数据库中,我有两个表通过外键关系链接在一起。
父表=controls.slot_table
子表=controls.IO_table
当新行插入到父表(A)中时,我想将一行插入到表 B 中,并通过外键将其链接到表 A 中的新行。
我的草稿看起来像这样(我知道它有语法错误,但这就是想法):
CREATE TRIGGER controls.Test_Insert_Linked_Row ON controls.slot_table AFTER INSERT AS
BEGIN
SET NOCOUNT ON
INSERT INTO controls.IO_table
(
point_description_A,
PLC_slot_ID
)
VALUES
(
'Test Automatically Generated Line',
t1.ID_auto
)
FROM controls.slot_table as t1
LEFT JOIN inserted as i
END
GO