创建触发器

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

你可能感兴趣的:(触发器)