在SQL2000中。我在一个表中插入新的数据,同时要向另一个表插入相关信息(不是全部信息)求触发器的语句?

2024-12-19 17:25:21
推荐回答(2个)
回答1:

-- 删除(假设有主键字段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

回答2:

从模板创建就能看到创建触发器的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