SQL: Deleting child records recursively

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default SQL: Deleting child records recursively

    I have a table of records that share a parent/child relationship. Ie:

    id | parentID | item
    1 | 0 | main item
    2 | 1 | secondary item
    3 | 2 | tertiary item

    If I delete item 1, I then want to automatically delete items 2 and 3, since
    they are children of 1.

    I was going to do a recursive function that deletes item 1, then goes into
    the db, looking for any item that had '1' as a parent id, delete them, and
    then repeat down the chain. Not a big deal, but thought I'd ask if there was
    already perhaps a built in SQL command that would do this in one query.

    -Darrel


    darrel Guest

  2. Similar Questions and Discussions

    1. Deleting multiple records
      Here's what I have... A table with 3 columns. Headings are (Name, Prayer Request, and Delete). A loop that goes through a Record Set and prints...
    2. Deleting duplicate records
      Jon, You didnt supply the DDL, so I can only point to existing practices to remove duplicate records.Here they are: INF: How to Remove...
    3. Deleting records against a list
      Let's say I have a database of 10,000 contacts. I send email out to them all and 200 of them bounce back. I collect those 200 bounces and parse...
    4. deleting records and keeping them
      hi i just wanted to know does any one if there is a way of deleting a record but also when the record is deleted it is lept in another file so that...
    5. deleting selection of records
      I have a page that populates with a set of records based on url parameters that are passed to it and it works great. I have added a checkbox and...
  3. #2

    Default Re: Deleting child records recursively

    I tend to use the logic from this article

    [url]http://www.sqlteam.com/item.asp?ItemID=8866[/url]

    Then have SQL like

    delete from t where lineage like '%/100/%'

    --
    Jules
    [url]http://www.charon.co.uk/charoncart[/url]
    Charon Cart 3
    Shopping Cart Extension for Dreamweaver MX/MX 2004



    Julian Roberts Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139