求一个出发器!

shadowno 2008-10-21 10:23:34
表中有两个字段,column1,column2 当column1的内容被改变时,触发器改变column2的内容
...全文
76 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
netcup 2008-10-21
  • 打赏
  • 举报
回复
create trigger upd_table on table for update as
if update(column1)
begin
if exists(select * from table a join inserted b on a.primaryid=b.primaryid where b.columns1='')
update a set a.columns2='' from table a join inserted b on a.prid=b.prid where b.columns1=''
else
update a set a.columns2='1' from table a join inserted b on a.prid=b.prid where b.columns1<>''

end

ChinaJiaBing 2008-10-21
  • 打赏
  • 举报
回复

create trigger trigger_t ON 表
for update
as
begin
if exists(select * from inserted where column1='')
update 表 set column2=''
else
update 表 set column2=1
end
pt1314917 2008-10-21
  • 打赏
  • 举报
回复


--> 测试数据: [s]
create table [s] (column1 varchar(10),column2 varchar(10))
insert into s select '12','aa'
go

create trigger tri_s on s for update
as
update s set column2 = case ltrim(isnull(column1,'')) when '' then '' else '1' end
go


update s set column1=' '
select * from [s]


update s set column1='3'
select * from [s]




shadowno 2008-10-21
  • 打赏
  • 举报
回复
up
shadowno 2008-10-21
  • 打赏
  • 举报
回复
没说太明白!
补充下,,

表中有两个字段,column1,column2 当column1的内容被变为空或时,column2改变为 ,column1的内容不为空或时,column2的内容改变为1
liangCK 2008-10-21
  • 打赏
  • 举报
回复
CREATE TRIGGER tri_test
ON tb
FOR UPDATE
AS
IF UPDATE(column1)
BEGIN
UPDATE a
SET column2='xx'
FROM tb AS a
JOIN deleted AS d
ON a.ID=d.ID
END
GO
天-笑 2008-10-21
  • 打赏
  • 举报
回复



create trigger trigger_name
on ta
for update
as
begin
if update(colname) and update(colname)...



end

go

34,590

社区成员

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

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