create trigger kk on test
For update,insert
AS
begin
update a set flag=(case when isnull(b.memo,'')='' then '1' else '2' end)
from test a join inserted b on a.tid=b.tid
end
--连insert的也省了
For update,insert
AS
begin
update a set flag=(case when isnull(b.memo,'')='' then '1' else '2' end)
from test a join inserted b on a.tid=b.tid
end
--连insert的也省了
解决方案 »
- SQL SERVER 为何查询数据库变量赋值时查不到数据?
- SQL2003 营业数据被清处了,,没有备份。有什么办法能恢复啊 ...
- 請問大家這條SQL語句有什麼錯誤(很簡單的SQL語句)?
- Sql语句问题。帮忙看看
- 请教专家:关于sql通过参数模糊查询的写法。
- 大神,求解决,关于SQL拼凑字符串的问题,速结贴
- 请问string类型变量最多可以赋值多少个字符???
- 急!!!分组查询问题。
- SQL 分布式查询问题
- 不装ORACLE CLIENT用ODBC怎么连接?
- ssis疑难问题,agent代理的时候,如果包连接了oracle的数据库的话,该作业就执行不了了?
- 头都大了。。关于论坛中的数据表。大家帮下忙。
create trigger kk on test
For update,insert
AS
if update(memo)
begin
update a set flag=(case when isnull(b.memo,'')='' then '1' else '2' end)
from test a join inserted b on a.tid=b.tid
end
还是不行啊
会不会和触发同一表有关系呢?
For update
AS
update a set flag=case when i.memo is null or i.memo='' then '1' else '2' end
from test a,inserted i where a.tID=i.tID
我是用程序更新表test,然后去到那一步就运行不下去了
按你的写法会否出现循环触发呢?
insert into test
select 'a001','aaa',32
union all
select 'a002','aab',22
union all
select 'a003','aac',4
union all
select 'a001','aac',4
create trigger kk on test
For update,insert
AS
if update(memo)
begin
update a set flag=(case when isnull(b.memo,'')='' then '1' else '2' end)
from test a join inserted b on a.tid=b.tid
end
--单个触发情况
update a
set memo='ttt'
from test a
where tID='a002'
--多个触发情况
update a
set memo='ttt'
from test a
where tID='a001'
drop table test--没有问题啊.
把触发器改成这样
create trigger kk on test
For update,insert
AS
if update(memo)
begin
update test set flag='2'
end
就可以通过,比较郁闷