在SQL2000中。我在一个表中插入新的数据,同时要向另一个表插入相关信息(不是全部信息)求触发器的语句?
同样的,在SQL2000中。我在一表中删除一数据,同时在另一个表中也要删除相关信息,的触发器语句,主要是触发器的创建语句,上课没怎么听,求高手解答,谢谢呀...........
同样的,在SQL2000中。我在一表中删除一数据,同时在另一个表中也要删除相关信息,的触发器语句,主要是触发器的创建语句,上课没怎么听,求高手解答,谢谢呀..........可要在SQL2000中运行哦.....谢谢呀!!!!
展开
2个回答
展开全部
-- 删除(假设有主键字段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
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'<trigger_name, sysname, trig_test>'
AND type = 'TR')
DROP TRIGGER <trigger_name, sysname, trig_test>
GO
CREATE TRIGGER <trigger_name, sysname, trig_test>
ON <table_name, sysname, pubs.dbo.sales>
FOR DELETE, INSERT, UPDATE
AS
BEGIN
RAISERROR (50009, 16, 10)
END
GO
IF EXISTS (SELECT name
FROM sysobjects
WHERE name = N'<trigger_name, sysname, trig_test>'
AND type = 'TR')
DROP TRIGGER <trigger_name, sysname, trig_test>
GO
CREATE TRIGGER <trigger_name, sysname, trig_test>
ON <table_name, sysname, pubs.dbo.sales>
FOR DELETE, INSERT, UPDATE
AS
BEGIN
RAISERROR (50009, 16, 10)
END
GO
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询