--> 测试数据: [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]
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
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
create trigger trigger_name
on ta
for update
as
begin
if update(colname) and update(colname)... end go
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
补充下,,表中有两个字段,column1,column2 当column1的内容被变为空或时,column2改变为 ,column1的内容不为空或时,column2的内容改变为1
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]
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
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