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

posted on 2015-03-20 22:08  御不凡  阅读(222)  评论(0编辑  收藏  举报