复制代码 代码如下:
IF EXISTS(SELECT * FROM sysobjects
WHERE 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 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
新闻热点
疑难解答