Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. cascading deletes

cascading deletes

Scheduled Pinned Locked Moved Database
sysadminhelptutorialquestionannouncement
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    neilsolent
    wrote on last edited by
    #1

    Hi I run what I thought was the most basic example of a table that allows a cascading delete: CREATE TABLE TEST ( ID tinyint NOT NULL, PARENT_ID tinyint NULL, CONSTRAINT PK PRIMARY KEY (ID), CONSTRAINT FK FOREIGN KEY (PARENT_ID) REFERENCES TEST(ID) ON DELETE CASCADE ) go I get the error: Introducing FOREIGN KEY constraint 'FK' on table 'TEST' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Msg 1750, Level 16, State 0, Server PEER170, Line 5 What am I doing wrong???

    cheers, Neil

    R 1 Reply Last reply
    0
    • N neilsolent

      Hi I run what I thought was the most basic example of a table that allows a cascading delete: CREATE TABLE TEST ( ID tinyint NOT NULL, PARENT_ID tinyint NULL, CONSTRAINT PK PRIMARY KEY (ID), CONSTRAINT FK FOREIGN KEY (PARENT_ID) REFERENCES TEST(ID) ON DELETE CASCADE ) go I get the error: Introducing FOREIGN KEY constraint 'FK' on table 'TEST' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Msg 1750, Level 16, State 0, Server PEER170, Line 5 What am I doing wrong???

      cheers, Neil

      R Offline
      R Offline
      Rob Graham
      wrote on last edited by
      #2

      Since the foreign key references a field in the same table, specifying cascade delete has the potential to create cycles. Not sure how you would ever insert the first record in this table, unless Id = Parent_id, and clearly that row would create an infinite loop on cascade delete , trying to recursively delete itself...

      N 1 Reply Last reply
      0
      • R Rob Graham

        Since the foreign key references a field in the same table, specifying cascade delete has the potential to create cycles. Not sure how you would ever insert the first record in this table, unless Id = Parent_id, and clearly that row would create an infinite loop on cascade delete , trying to recursively delete itself...

        N Offline
        N Offline
        neilsolent
        wrote on last edited by
        #3

        Thanks for that. So it is basically a limitation of SQL Server. The first row (a "top level" row) would be inserted with parent_id = NULL, therefore there would be no infinite recursion problem. But no worries, I can workaround it.

        cheers, Neil

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups