创建触发器

时间:2015-03-20 23:41:14   收藏:0   阅读:308

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
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!