我对SQL触发器不是很了解,但是最近要用到它,所以就上网查了一下。会写一些比较简单的了。在这里做一个记录,以便以后自己使用
CREATE TRIGGER deletName ON [dbo].[a]
FOR DELETE
AS
begin
delete from b where classid = (select id from deleted)
end
第一句,deletName是这个触发器的名字,[dbo].[a]表名,表示,如果这个表中的信息改动,则B表中也要改动。
第二句,delete是选择,主表a在什么情况下从表B也会变,这里可以写insert,update
第五句,就是你要操作的名子了。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
第二句,delete是选择,主表a在什么情况下从表B也会变,这里可以写insert,update
第五句,就是你要操作的名子了。