大致情况如下:(本表的After触发器去修改别的表的数据)
CREATE TRIGGER Trg_PreProductionUpdate ON dbo.PreProduction
AFTER UPDATE
AS
句一:update schedule set updatetime=getdate()
句二:update schedule set updatetime=getdate() where +条件
句一执行正确,而句二执行不正确,为什么?
...全文
388打赏收藏
关于触发器问题(请各位帮帮忙,如正确,立刻给分)
大致情况如下:(本表的After触发器去修改别的表的数据) CREATE TRIGGER Trg_PreProductionUpdate ON dbo.PreProduction AFTER UPDATE AS 句一:update schedule set updatetime=getdate() 句二:update schedule set updatetime=getdate() where +条件 句一执行正确,而句二执行不正确,为什么?
我已发现问题,原因不在于那些句子(简单的SQL句子,经检验都是对的)
if exists(select * from schedule where +条件)
update schedule set updatetime=getdate() where +条件
这样就对了,大家有兴趣的话,可以试一试,这是昨晚我们经理逼出来的,
搞不好不让回家。现在说出来也算增长大家的见识。
(在一次谢谢各位的回答,但是不会有分,因为上面的都试过了,很简单的条件)
CREATE TRIGGER Trg_PreProductionUpdate ON dbo.PreProduction
AFTER UPDATE
AS
declare @条件 varchar(1000)
set @条件='1=1'
exec('update schedule set updatetime=getdate() where '+条件)
go