bill表中的actualmoney这列值是数值型的,只要这列值发生变化就让它自动变为0,这样的触发器完整写法是什么,请提供一下完整的写法,谢谢
解决方案 »
- SQL2000 DELETE 某些表数据无法删除
- 请教一条查唯一记录的SQL语句。
- SQL语句group by不支持ntext类型啊
- sp_addlinkedserver 登陆失败问题
- job一启动,这个JOB的进程都是sleeping
- ☆★☆数据表中字段中的数据不为NULL,但也没有数据,怎样查询?大家都来帮忙呀
- 如何实现这样一个insert语句?
- <分不多了,见凉>关于RerultSet判断结果的问题(附代码)
- group by 分组的问题
- WHY?:数据库 'mydb' 的日志已满。请备份该数据库的事务日志以释放一些日志空间。
- sql2005更新text类型字段超时
- 分组统计更新数据问题
for update
as
if update(actualmoney)
update t set actualmoney=0 from inserted i ,tb t where i.id=t.id
楼上的,条件怎么加呢,我是菜鸟,if update(actualmoney) and actualmoney=2*money 这样写告诉我不对,麻烦你再帮我一下吧
create trigger tri_tb_up on tb
for update
as
if update(actualmoney)
update t set actualmoney=0 from inserted i ,tb t where i.id=t.id AND t.actualmoney = t.money * 2
ON tb
FOR UPDATE
AS
IF UPDATE(actualmoney)
UPDATE t
SET actualmoney = 0
FROM inserted i,
tb t
WHERE i.id = t.id
AND t.actualmoney = t.money * 2
create trigger tr_bill
on bill after insert,update
as
begin
update a
set a.actualmoney=0
from bill a
inner join inserted b
on a.[money]=b.[money] and a.actualmoney=b.actualmoney
where b.actualmoeny=b.[money]*2
end
为什么不能写在if update(actualmoney)后面呢,首先判断该列是否被修改和是否是money的2倍,然后再变0