-- 删除(假设有主键字段ID):
create trigger trgReplicateDeletion on dbo.TableA
for delete
as
begin
delete from TableB where id in (select id from deleted)
end
-- 插入
create trigger trgReplicateInsertion on dbo.TableA
for insert
as
begin
insert into TableB(field1, field2, ...)
select field1, field2, ... from inserted
end
从模板创建就能看到创建触发器的SQL了
IF EXISTS (SELECT name
FROM sysobjects
WHERE name = N'
AND type = 'TR')
DROP TRIGGER
GO
CREATE TRIGGER
ON
FOR DELETE, INSERT, UPDATE
AS
BEGIN
RAISERROR (50009, 16, 10)
END
GO