码迷,mamicode.com
首页 > 其他好文 > 详细

创建触发器

时间:2015-03-20 23:42:44      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

CREATE TRIGGER    [dbo].[table1_column1]  ON [dbo].table1
for INSERT, UPDATE
--after INSERT, UPDATE
AS
DECLARE @canshu1 varchar(30),
        @rq datetime,
        @rq2 datetime
SELECT @canshu1 = canshu1,
       @rq=rq
FROM  inserted
 set @rq2=(select rq2 from table2 where rq2=@canshu1)
 if(@rq>@rq2)
   update table2 set rq2=@rq where canshu1=@canshu1
 update table2 set updateTime=getdate() where canshu1=@canshu1

GO

创建触发器

标签:

原文地址:http://www.cnblogs.com/yubufan/p/4354727.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!