关于SQL-Server中触发器的问题。请高人指点下
问题1:
如果创建一个这样的触发器
--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