删除行时,SQL触发器中的UPDATED()函数是否返回true?

时间:2015-03-26 18:21:43

标签: sql-server

当你对一个带触发器的表运行DELETE语句时,在该触发器中UPDATE( colName )函数会返回true吗?

1 个答案:

答案 0 :(得分:2)

没有。 UPDATE(colName)仅对INSERT和UPDATE返回TRUE

set nocount on
go
create table test ( cola nvarchar(10), colB int default(0) ) 
go 
create trigger tr_test on test for insert,update,delete
as
begin 
    select case when update(cola) then 'yes' else 'no' end as ColA_Updated, 
           case when update(colb) then 'yes' else 'no' end as ColB_Updated
end 
go 

-- This outputs 'yes', 'yes'
insert into test (cola) values ( 'a' ) 

-- This outputs 'yes', 'no'
update test set cola = 'b' 

-- This outputs 'no', 'no'
delete from test where 1=0

-- This outputs 'no', 'no'
delete from test 

go
drop trigger tr_test
drop table test
go