22,210
社区成员
发帖
与我相关
我的任务
分享
if object_id('tb') is not null
drop table tb
go
create table tb(id int,name varchar(10))
insert into tb
select 1,'wang'
go
if object_id('tb_log') is not null
drop table tb_log
create table tb_log(id int ,name varchar(10),dml varchar(200))
go
create trigger t_tb
on tb
for insert ,delete,update
as
begin
if not exists(select 1 from deleted)
insert into tb_log
select *,'insert' from inserted
else
if not exists(select 1 from inserted)
insert into tb_log
select * ,'delete' from deleted
else
insert into tb_log
select * ,'update before' from deleted
union all
select * ,'update after' from inserted
end