Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3808540
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:09:49+00:00 2026-05-19T15:09:49+00:00

I have a structure of folders like this: Folder1 Folder1.1 Folder1.2 Folder2 Folder2.1 Folder2.1.1

  • 0

I have a structure of folders like this:

Folder1
  Folder1.1
  Folder1.2
Folder2
  Folder2.1
    Folder2.1.1
and so on..

The question is how to cascade delete them(i.e. when remove folder2 all children are also deleted). I can’t set an ON DELETE action because MSSQL does not allow it. Can you give some suggesions?

UPDATE: I wrote this stored proc, can I just leave it or it needs some modifications?

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE sp_DeleteFoldersRecursive
    @parent_folder_id int
AS
BEGIN
    SET NOCOUNT ON;

    IF @parent_folder_id = 0 RETURN;

    CREATE TABLE #temp(fid INT );

    DECLARE @Count INT;

    INSERT INTO #temp(fid)
    SELECT FolderId FROM Folders WHERE FolderId = @parent_folder_id;

    SET @Count = @@ROWCOUNT;

    WHILE @Count > 0
    BEGIN
        INSERT INTO #temp(fid) 
            SELECT FolderId FROM Folders WHERE EXISTS
                   (SELECT FolderId  FROM #temp
                    WHERE Folders.ParentId = #temp.fid)
             AND  NOT EXISTS
                  (SELECT FolderId FROM #temp
                   WHERE Folders.FolderId = #temp.fid);    

             SET @Count = @@ROWCOUNT;         
    END

    DELETE Folders FROM Folders INNER JOIN #temp ON Folders.FolderId = #temp.fid; 
    DROP TABLE #temp;
END
GO
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T15:09:50+00:00Added an answer on May 19, 2026 at 3:09 pm

    Normally it’s be a stored proc or INSTEAD OF trigger.

    That is:

    • generate your hierarchy of Folder2 from parameter/DELETED (recursive CTE approach for example))
    • delete this hierarchy in one DELETE statement

    The circular cascade/foreign key violations will not fire.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a folder structure set up like this: ~/Projects emacs package1 package1-helpers
I have a structure like this: <ul> <li>text1</li> <li>text2</li> <li>text3</li> </ul> How do I
Currently I have a structure like this: A | +--B | +--C It's mapped
If I have a folder structure that looks like this: / /bin/myComponent.cfc /reports/index.cfm How
I have a project where the directory structure is like this: $projectroot | +---------------+----------------+
First of all, i'm a Graphic designer so please ignore if this programming question
I'm trying to build an archetype structure like this, a webapp with some custom
I have a project structure that looks like the following: [Solution Name] doc (documentation)
All, I'm pretty new to AS3, so this is probably a very trivial question.
I have a structure which I need to populate and write to disk (several

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.