Microsoft SQL Server 觸發器更新、刪除、插入表


//表插入CREATE TRIGGER INSERTDATE//INSERTDATE為觸發器名稱

ON A1 AFTER INSERT AS

BEGIN

INSERT INTOA2 (A2NAME) SELECT A1NAME FROM INSERTED

END

表同步插入

CREATE TRIGGER DELETEDATE//DELETEDATE 為觸發器名
ON A1 AFTER DELETE ASBEGIN            DELETE A2 WHERE A2 NAME IN(SELECT A1 NAME FROM DELETED)END//表同步刪除CREATE TRIGGER UPDATEDATE //Updatedate為觸發器名ON A1 AFTER UPDATE ASBEGIN            UPDATE A2 SET A2.A2NAME=A1.A1NAME FROM A1 where A2.ID=A1.ID //將A1表內容傳給A2END//表同步更新
//A1,A2,均為表名,A1NAME,ID為A1表列名,A2NAME,ID為A2表列名


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com