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

  • SEARCH
  • Home
  • 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 654019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:26:51+00:00 2026-05-13T22:26:51+00:00

Is there a tool that will let you visualize a SQL Server 2008 cascade

  • 0

Is there a tool that will let you visualize a SQL Server 2008 cascade tree? I’m having troubles with items not being able to be deleted and I would like to see the path that SQL takes.

  • 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-13T22:26:52+00:00Added an answer on May 13, 2026 at 10:26 pm

    I think this is what you are after:

    http://www.sqlservercentral.com/scripts/foreign+keys/69110/

    if you don’t want to give them an e-mail, here is the code:

    IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ShowDeleteTree]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
    DROP PROCEDURE [dbo].[ShowDeleteTree]
    GO
    
    CREATE PROCEDURE dbo.ShowDeleteTree
        @TableName varchar(128),
        @PrintDepth int = 9
    AS  
    
    -- print tree of dependencies for any table
    declare 
        @p varchar(128),
        @c1 varchar(128),
        @c2 varchar(128),
        @c3 varchar(128),
        @c4 varchar(128),
        @c5 varchar(128),
        @c6 varchar(128),
        @c7 varchar(128),
        @delaction varchar(20),
        @char9 varchar(10)
    
    
    set @p = @TableName
    set @char9 = '-->'
    
    -- view as text
    
    -- hierarchy -------------------------------------------------------------
    set nocount on
    declare @loop int
    declare @dep table( child varchar(100), parent varchar(100), pass int, delaction varchar(20))
    
    -- dependency list
    insert into @dep
    select distinct object_name(parent_object_id), object_name(referenced_object_id), 0, delete_referential_action_desc
    from sys.foreign_keys 
    where parent_object_id <> referenced_object_id
    order by 1,2
    
    
    
    -- bottom: children that are never parents
    update
        @dep
    set
        pass = 1
    where
        child not in 
            (
                select 
                    parent
                from
                    @dep
            )
    
    
    -- middle to top: parents where children have been processed
    set @loop = 2
    while @loop < 10
    begin
        update
            @dep
        set
            pass = @loop
        where
            pass = 0
        and
            parent in 
                (
                    -- select parents where all children have been processed
                    select
                        parent
                    from
                        @dep d1
                    where
                        pass = 0
                    and
                        not exists
                            (select * from @dep d2 where d1.child=d2.parent and d2.pass=0)
                )
    
        set @loop = @loop + 1
    end
    
    select parent as 'ImmediateParent', delaction as 'DeleteAction' from @dep where child = @p
    print ''
    
    print '-- children of'
    print @p
    
    if exists (select * 
    from sys.tables t join sys.triggers tr on t.object_id=tr.parent_id 
    where t.name = @p
    and tr.is_instead_of_trigger=1
    and objectproperty(tr.object_id,'ExecIsDeleteTrigger')=1)
        print 'Has "Instead Of Delete" Trigger so parents cannot cascade delete it.
    
    '
    
    
    --1
    select @c1=min(child) from @dep where parent = @p
    while @c1 is not null
    begin
        select @delaction = delaction from @dep where child=@c1 and parent=@p
        if @printdepth >=1 print @char9+@c1+' '+@delaction
        --2
        select @c2=min(child) from @dep where parent = @c1
        while @c2 is not null
        begin
            select @delaction = delaction from @dep where child=@c2 and parent=@c1
            if @printdepth >=2 print @char9+@char9+@c2+' '+@delaction
            --3
            select @c3=min(child) from @dep where parent = @c2
            while @c3 is not null
            begin
                select @delaction = delaction from @dep where child=@c3 and parent=@c2
                if @printdepth >=3 print @char9+@char9+@char9+@c3+' '+@delaction
                --4
                select @c4=min(child) from @dep where parent = @c3
                while @c4 is not null
                begin
                    select @delaction = delaction from @dep where child=@c4 and parent=@c3
                    if @printdepth >=4 print @char9+@char9+@char9+@char9+@c4+' '+@delaction
                    --5
                    select @c5=min(child) from @dep where parent = @c4
                    while @c5 is not null
                    begin
                        select @delaction = delaction from @dep where child=@c5 and parent=@c4
                        if @printdepth >=5 print @char9+@char9+@char9+@char9+@char9+@c5+' '+@delaction
                        --6
                        select @c6=min(child) from @dep where parent = @c5
                        while @c6 is not null
                        begin
                            select @delaction = delaction from @dep where child=@c6 and parent=@c5
                            if @printdepth >=6 print @char9+@char9+@char9+@char9+@char9+@char9+@c6+' '+@delaction
                            --7
                            select @c7=min(child) from @dep where parent = @c6
                            while @c7 is not null
                            begin
                                select @delaction = delaction from @dep where child=@c7 and parent=@c6
                                if @printdepth >=7 print @char9+@char9+@char9+@char9+@char9+@char9+@char9+@c7+' '+@delaction
                                select @c7=min(child) from @dep where parent = @c6 and child > @c7
                            end
                            --7
                            select @c6=min(child) from @dep where parent = @c5 and child > @c6
                        end
                        --6
                        select @c5=min(child) from @dep where parent = @c4 and child > @c5
                    end
                    --5
                    select @c4=min(child) from @dep where parent = @c3 and child > @c4
                end
                --4
                select @c3=min(child) from @dep where parent = @c2 and child > @c3
            end
            --3
            select @c2=min(child) from @dep where parent = @c1 and child > @c2
        end
        --2
        select @c1=min(child) from @dep where parent = @p and child > @c1
    end
    --1
    
    return 0
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 386k
  • Answers 386k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Pretty well-suited to sed: # Using your matching criterion (first… May 14, 2026 at 11:50 pm
  • Editorial Team
    Editorial Team added an answer Consider these Categories for NSImage for ways in which you… May 14, 2026 at 11:50 pm
  • Editorial Team
    Editorial Team added an answer In the recursive section of the CTE, one of the… May 14, 2026 at 11:50 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.