关于触发器问题(请各位帮帮忙,如正确,立刻给分)

rocllllll 2003-10-15 05:41:11
大致情况如下:(本表的After触发器去修改别的表的数据)
CREATE TRIGGER Trg_PreProductionUpdate ON dbo.PreProduction
AFTER UPDATE
AS
句一:update schedule set updatetime=getdate()
句二:update schedule set updatetime=getdate() where +条件

句一执行正确,而句二执行不正确,为什么?
...全文
38 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
rocllllll 2003-10-16
  • 打赏
  • 举报
回复
我已发现问题,原因不在于那些句子(简单的SQL句子,经检验都是对的)
if exists(select * from schedule where +条件)
update schedule set updatetime=getdate() where +条件
这样就对了,大家有兴趣的话,可以试一试,这是昨晚我们经理逼出来的,
搞不好不让回家。现在说出来也算增长大家的见识。
(在一次谢谢各位的回答,但是不会有分,因为上面的都试过了,很简单的条件)
zjcxc 元老 2003-10-15
  • 打赏
  • 举报
回复
--如果条件是变量中,就用

CREATE TRIGGER Trg_PreProductionUpdate ON dbo.PreProduction
AFTER UPDATE
AS
declare @条件 varchar(1000)
set @条件='1=1'
exec('update schedule set updatetime=getdate() where '+条件)
go
CrazyFor 2003-10-15
  • 打赏
  • 举报
回复
update schedule set updatetime=getdate() where +条件
改成:
exec('update schedule set updatetime=getdate() where '+条件)
wzh1215 2003-10-15
  • 打赏
  • 举报
回复
都是五角星,看来没我们三角星的份了!
pengdali 2003-10-15
  • 打赏
  • 举报
回复
CREATE TRIGGER Trg_PreProductionUpdate ON dbo.PreProduction
AFTER UPDATE
AS
update schedule set updatetime=getdate() where 1=1

没有问题。
yujohny 2003-10-15
  • 打赏
  • 举报
回复
上面这句只要你条件写的对,那就应该执行正确
zjcxc 元老 2003-10-15
  • 打赏
  • 举报
回复
应该是你的条件错了.

最好贴出全部代码.
yujohny 2003-10-15
  • 打赏
  • 举报
回复
不正确,出现什么情况????

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧