IF EXISTS(SELECT * FROM sysobjects WHERE name='tr_Users_OnUpdate' AND TYPE='TR') DROP TRIGGER tr_Users_OnUpdate GO --这里呢创建触发器与存储过程类似(都是DDL) --先判断如否存在同名触发器就删除然后重建 CREATE TRIGGER tr_Users_OnUpdate ON Users FOR UPDATE AS PRINT ‘Users表已发生修改' GO
--添加留言的触发器 IF EXISTS(SELECT name FROM sysobjects WHERE name='tr_LeaveWord_Add' AND TYPE='TR') DROP TRIGGER tr_LeaveWord_Add GO CREATE TRIGGER tr_LeaveWord_Add ON WordInfo FOR INSERT AS UPDATE UserInfo SET LeaveCount=LeaveCount+1 WHERE UserID=(SELECT TOP 1 UserID FROM Inserted) GO