新手提問:如何創建這樣的觸發器!
有一個表,現在想當在這個表裏新加一條紀錄的時候,能在一個表裏把新加的紀錄添加進去,刪除一條紀錄的時候,也能夠在另一個表裏把刪除的紀錄添加進去,這幾個表的結構都是一模一樣的,請問該怎麼寫這樣的觸發器呢?
------解决方案--------------------假如有
t1
t2
t3
當t1新增記錄時,同時保存在t2表中
當t1刪除時,把刪除的記錄保存在t3表中
create trigger tri_ins on t1
after insert
as
insert into t2
select * from inserted
--
create trigger tri_del on t1
after delete
as
insert into t3
select * from deleted
------解决方案--------------------create trigger tri_test
on [TableName]
for update,insert,delete
as
insert [Table] select * from inserted
insert [Table] select * from deleted