无法创建删除触发器,因为表具有带有级联 DELETE 的 FOREIGN KEY

发布于 2024-09-13 22:09:48 字数 1258 浏览 6 评论 0原文

我正在尝试创建一个删除触发器。我有一个名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心头的小情儿 2024-09-20 22:09:48

INSTEAD OF 触发器用于修改不能使用DML 的视图。
尝试使用 BEFOREAFTER 触发器。

Oracle RDBMS

INSTEAD OF triggers are for modifying views which you can't use DML.
Try with a BEFORE or AFTER trigger.

Oracle RDBMS

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文