漫漫技术人生路

C#

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  234 随笔 :: 0 文章 :: 30 评论 :: 8 引用

公告

我有一个数据表test,testnum(int)和testtext(varchar),想写一个触发器来满足当testnum大于0少于20的时候,testtext显示“你好”,如果testnum大于20的时候testtext就显示“再见”,我想用update触发器,因为testnum是由另外的表控制的。

应该还需要insert触发器吧

create trigger it_test on test
instead of insert
as
insert into test(testnum,testtext)
select testnum,case when testnum between 0 and 20 then '你好'
when testnum > 20 then '再见'
end
from inserted
go
create trigger tu_test on test
for update
as
if update(testnum) and exists(select 1 from inserted i,deleted d where i.testnum<>d.testnum)
begin
update test
set testtext=case when testnum between 0 and 20 then '你好'
when testnum > 20 then '再见'
end
end
http://community.csdn.net/Expert/topic/5476/5476519.xml?temp=.4222528

posted on 2007-05-08 13:10 javaca88 阅读(53) 评论(0) 编辑 收藏
(评论功能已被博主禁用)