1个回答
推荐于2016-03-16
展开全部
create trigger tr_a
on a
for insert,update,delere as
begin
IF EXISTS(SELECT 1 FROM inserted) AND NOT EXISTS(SELECT 1 FROM deleted)
BEGIN
-- 插入触发.
INSERT INTO B
SELECT
inserted.a
FROM
inserted;
END;
IF EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted)
BEGIN
-- 更新触发.
DELETE FROM B WHERE a in ( SELECT a FROM deleted);
INSERT INTO B
SELECT
inserted.a
FROM
inserted;
END;
IF NOT EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted)
BEGIN
-- 删除触发
DELETE FROM B WHERE a in ( SELECT a FROM deleted);
END;
on a
for insert,update,delere as
begin
IF EXISTS(SELECT 1 FROM inserted) AND NOT EXISTS(SELECT 1 FROM deleted)
BEGIN
-- 插入触发.
INSERT INTO B
SELECT
inserted.a
FROM
inserted;
END;
IF EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted)
BEGIN
-- 更新触发.
DELETE FROM B WHERE a in ( SELECT a FROM deleted);
INSERT INTO B
SELECT
inserted.a
FROM
inserted;
END;
IF NOT EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted)
BEGIN
-- 删除触发
DELETE FROM B WHERE a in ( SELECT a FROM deleted);
END;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询