
[英]SQL-SERVER Procedure How do i insert row one table then insert row into another table link to another table as foreign key
[英]SQL Server: If a row is inserted in one table, how do I write a trigger to insert that same row in a different table?
我不确定如何创建这个触发器。当在publishers 表中插入一行时,我需要在pub_info 表中添加一行。 完全相同的行。 SQL服务器
CREATE TRIGGER checkCity
ON pub_info
AFTER INSERT
AS
IF -- a row is inserted into publishers table,
-- how do I add the same row into pub_info table?
INSERT VALUES(@pub_id, NULL, 'new publishers')
BEGIN
END;
您必须在publishers
表上而不是在pub_info
上创建触发器。 插入的数据在触发器的INSERTED表中可用
CREATE TRIGGER checkCity
ON publishers
AFTER INSERT
AS
BEGIN
INSERT INTO pub_info(pubid, pubname, pub_description)
SELECT pubid, pubname, pub_description
FROM INSERTED;
END;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.