无法创建删除触发器,因为表具有带有级联 DELETE 的 FOREIGN KEY
我正在尝试创建一个删除触发器。我有一个名为 Nemanet_Navigation 的导航表。该表本身有一个外键,但在选择表的关系时,我在 INSERT 和 UPDATE 规范中选择了 - 删除规则无操作。所以我不选择Cascading。然后我有这个触发器:
CREATE TRIGGER Del_Nemanet_Navigation ON Nemanet_Navigation
INSTEAD OF DELETE
AS
CREATE TABLE #Table(
Nav_ID uniqueidentifier
)
INSERT INTO #Table (Nav_ID)
SELECT Nav_ID
FROM deleted
DECLARE @C uniqueidentifier
SET @c = 0
WHILE @C <> (SELECT COUNT(Nav_ID) FROM #Table) BEGIN
SELECT @c = COUNT(Nav_ID) FROM #Table
INSERT INTO #Table (Nav_ID)
SELECT Nemanet_Navigation.Nav_ID
From Nemanet_Navigation
LEFT OUTER JOIN #Table ON Nemanet_Navigation.Nav_ID = #Table.Nav_ID
WHERE Nemanet_Navigation.Nav_pID IN (SELECT Nav_ID FROM #Table)
AND #Table.Nav_ID IS NULL
END
DELETE Nemanet_Navigation
FROM Nemanet_Navigation
INNER JOIN #Table ON Nemanet_Navigation.Nav_ID = #Table.Nav_ID
但我收到以下错误:
无法在“Nemanet_Navigatin”上创建“INSTEAD OF DELETE”触发器“Del_Nemanet_Navigation”。
这是因为表有一个带有级联 DELETE 的 FOREIGN KEY。但我的 Nemante_Navigation 表有删除规则 - 无操作(但由于某种我不知道的原因标记为灰色 - 我无法更改它)。触发器位于 Nemanet_Navigation Table 下名为 Triggers 的文件夹中。有人可以帮忙吗?
I am trying to create a Delete trigger. I have this navigation table which is called Nemanet_Navigation. The table has a foreign key to itself but when selecting relationship for the table I have in INSERT and UPDATE Specification selected - Delete Rule NO Action. So I do not select Cascading. Then I have this trigger:
CREATE TRIGGER Del_Nemanet_Navigation ON Nemanet_Navigation
INSTEAD OF DELETE
AS
CREATE TABLE #Table(
Nav_ID uniqueidentifier
)
INSERT INTO #Table (Nav_ID)
SELECT Nav_ID
FROM deleted
DECLARE @C uniqueidentifier
SET @c = 0
WHILE @C <> (SELECT COUNT(Nav_ID) FROM #Table) BEGIN
SELECT @c = COUNT(Nav_ID) FROM #Table
INSERT INTO #Table (Nav_ID)
SELECT Nemanet_Navigation.Nav_ID
From Nemanet_Navigation
LEFT OUTER JOIN #Table ON Nemanet_Navigation.Nav_ID = #Table.Nav_ID
WHERE Nemanet_Navigation.Nav_pID IN (SELECT Nav_ID FROM #Table)
AND #Table.Nav_ID IS NULL
END
DELETE Nemanet_Navigation
FROM Nemanet_Navigation
INNER JOIN #Table ON Nemanet_Navigation.Nav_ID = #Table.Nav_ID
But I get the following error:
Cannot create INSTEAD OF DELETE trigger 'Del_Nemanet_Navigation' on 'Nemanet_Navigatin'.
This is because table has a FOREIGN KEY WITH cascading DELETE. But my Nemante_Navigation table has delete rule - no action (but is marked gray for some reason I do not know - and I can not change it). The trigger is in folder called Triggers under the Nemanet_Navigation Table. Can anybody help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
INSTEAD OF
触发器用于修改不能使用DML
的视图。尝试使用
BEFORE
或AFTER
触发器。Oracle RDBMS
INSTEAD OF
triggers are for modifying views which you can't useDML
.Try with a
BEFORE
orAFTER
trigger.Oracle RDBMS