--例子 create table tb(id int,name varchar(10)) gocreate table tt(id int,name varchar(10),lb varchar(10),[date] datetime) gocreate trigger cfq on tb for insert,delete,update asif @@rowcount=0 returndeclare @count_ins int declare @count_del int select @count_ins=count(1) from inserted select @count_del=count(1) from deletedif(@count_ins>0 and @count_del=0) begin insert into tt select id,name,'insert',getdate() from inserted endif(@count_ins>0 and @count_del>0) begin insert into tt select id,name,'update',getdate() from inserted endif(@count_ins=0 and @count_del>0) begin insert into tt select id,name,'delete',getdate() from deleted end goinsert into tb select 1,'song' insert into tb select 2,'asong' godelete tb where id=1 goupdate tb set name='aa' where id=2 goselect * from tb select * from ttdrop trigger cfq drop table tb,tt
select * from syscolumns where cdefault<>0
学习楼上 :) select * from syscolumns a,sysobjects b where a.id=b.id and a.cdefault<>0 and b.id=object_id('tb')修改下
create table tb(id int,name varchar(10))
gocreate table tt(id int,name varchar(10),lb varchar(10),[date] datetime)
gocreate trigger cfq on tb
for insert,delete,update
asif @@rowcount=0 returndeclare @count_ins int
declare @count_del int
select @count_ins=count(1) from inserted
select @count_del=count(1) from deletedif(@count_ins>0 and @count_del=0)
begin
insert into tt select id,name,'insert',getdate() from inserted
endif(@count_ins>0 and @count_del>0)
begin
insert into tt select id,name,'update',getdate() from inserted
endif(@count_ins=0 and @count_del>0)
begin
insert into tt select id,name,'delete',getdate() from deleted
end
goinsert into tb select 1,'song'
insert into tb select 2,'asong'
godelete tb where id=1
goupdate tb set name='aa' where id=2
goselect * from tb
select * from ttdrop trigger cfq
drop table tb,tt
select * from syscolumns a,sysobjects b where a.id=b.id and a.cdefault<>0 and b.id=object_id('tb')修改下