27,579
社区成员
发帖
与我相关
我的任务
分享
--测试数据
if not object_id(N'test_a') is null
drop table test_a
Go
CREATE TABLE DBO.test_a(
id INT,
flag INT,
[time] DATETIME
)
INSERT INTO dbo.test_a(id,flag,[time])
SELECT 1,1,N'2017-01-01 11:11:11'
UNION ALL
SELECT 2,0,N'2017-02-02 11:11:11'
--测试数据结束
--创建触发器
CREATE TRIGGER dbo.trtest_a
ON dbo.test_a
FOR UPDATE
AS
BEGIN
UPDATE test_a
SET [time] = GETDATE()
FROM inserted
WHERE inserted.id = test_a.id
AND inserted.flag = 0
END
GO
--测试
UPDATE test_a SET flag = 0 WHERE id=1
SELECT * FROM test_a