SQL stepless classification recursive deletion subclass

Source: Internet
Author: User
1 create procedure usp_catalogdeletechild
2 (
3 @ catalogid nvarchar (50)
4)
5as
6 set nocount on
7
8 declare @ childcatalogid nvarchar (50)
9 declare @ loop int
10 declare @ totalrow int
11
12 Delete from cms_catalog where [ID] = @ catalogid
13 begin
14 ---------- recursion, using temporary tables
15 select [ID], identity (INT) As I into # TMP from cms_catalog where parentid = @ catalogid
16 set @ totalrow = @ rowcount
17 set @ loop = 1
18
19 while (@ loop <= @ totalrow)
20 begin
21 select @ childcatalogid = [ID] From # TMP where I = @ Loop
22 set @ loop = @ loop + 1
23 exec usp_catalogdeletechild @ childcatalogid
24 end
25end
26go
27

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.