:: -- --------sql触发器-------------------------------------------------
1 .删除
CREATE TRIGGER [ Delete_TopAlexa ] ON [ dbo ] . [ tb_WebSite ]
FOR DELETE
AS
BEGIN TRANSACTION
delete from tb_alexa where websiteid = ( select websiteid from deleted)
delete from tb_top100 where websiteid = ( select websiteid from deleted)
IF ( @@ERROR <> 0 ) -- 如果有错误
BEGIN
ROLLBACK TRANSACTION -- 回滚
END
COMMIT TRANSACTION -- 提交事务
2 .更新
create trigger Test_OK
on ok
for update
as
if update (name)
begin
update sname set sname.s_name = ok.name from ok,sname
where sname.n_id = ok.n_id
end
说明: 关键字都用大写的蓝色字体标出, 斜体字代表用户字符串
triggername-------------触发器的名字@H_301_282@
mainTableName------主表名@H_301_282@
childTableName-------子表名@H_301_282@
ctbid-------------------------子表的字段@H_301_282@
mid--------------------------主表的比较字段@H_301_282@
::----------sqlite触发器-------------------------------------------------
1.删除
CREATE TRIGGERtriggername@H_301_282@AFTERDELETEONmainTableName@H_301_282@FOREACHROW
BEGIN
DELETEFROMchildTableName@H_301_282@WHEREctbid@H_301_282@=OLD.mid@H_301_282@;
END;
2.更新
CREATE TRIGGERtriggername@H_301_282@AFTERUPDATEONmainTableName@H_301_282@ FOREACHROW
BEGIN
UPDATEchildTableName@H_301_282@SETctbid @H_301_282@=NEW.mid
WHERE childTableName@H_301_282@.ctbid@H_301_282@= OLD.mid;
END;