日期:2014-05-17 浏览次数:20544 次
CREATE TRIGGER reminder
ON titles
FOR INSERT, UPDATE
CREATE TRIGGER Tress
ON [dbo].[Address]
AFTER UPDATE
--1.在一个Trigger中分别处理insert,update,delete
create trigger add_iud
on address for insert,update,delete
as
--1.1 insert
if exists(select 1 from inserted) and not exists(select 1 from deleted)
begin
...
end
--1.2 update
if exists(select 1 from inserted) and exists(select 1 from deleted)
begin
...
end
--1.3 delete
if not exists(select 1 from inserted) and exists(select 1 from deleted)
begin
...
end
--2.给子表插数据
create trigger add_子表
on address for insert
as
insert 子表(字段...)
select 字段... from inserted
--3.同意楼上,触发器不需要太复杂.
create trigger reminder
on titles
for insert,update
as
begin
if exists(select 1 from inserted) and not exists(select 1 from deleted)
begin
[insert对应的代码]
end
if exists(select 1 from inserted) and exists(select 1 from deleted)
begin
[update对应的代码]
end
end
create trigger Tress
on dbo.Address
after UPDATE
as
begin
[触发器代码]
insert into [Address表的子表]([字段列表]) values([字段值列表])
end