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. SQL Server script to find table dependencies

SQL Server script to find table dependencies

Scheduled Pinned Locked Moved Database
htmldatabasesql-servercomsysadmin
14 Posts 5 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.
  • J Offline
    J Offline
    jujiro
    wrote on last edited by
    #1

    If you are fanatic about normalization, I am sure you know the pains associated with it. Deletion of a row at a top level table can become a project very quickly due the child tables dependencies, which can run several levels deep. I have a script to do that. Please feel free to download and share.

    P L M 3 Replies Last reply
    0
    • J jujiro

      If you are fanatic about normalization, I am sure you know the pains associated with it. Deletion of a row at a top level table can become a project very quickly due the child tables dependencies, which can run several levels deep. I have a script to do that. Please feel free to download and share.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      If it's so good and useful, please write an article. And if you run into that problem often I recommend using referential integrity.

      J 1 Reply Last reply
      0
      • J jujiro

        If you are fanatic about normalization, I am sure you know the pains associated with it. Deletion of a row at a top level table can become a project very quickly due the child tables dependencies, which can run several levels deep. I have a script to do that. Please feel free to download and share.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        jujiro wrote:

        Deletion of a row at a top level table can become a project very quickly due the child tables dependencies, which can run several levels deep.

        "Cascading delete". Most modern databases do.

        Bastard Programmer from Hell :suss:

        M 1 Reply Last reply
        0
        • P PIEBALDconsult

          If it's so good and useful, please write an article. And if you run into that problem often I recommend using referential integrity.

          J Offline
          J Offline
          jujiro
          wrote on last edited by
          #4

          I was going to curse you out but then saw that you are a legend at The Code Project, so I won't. > Write an article: Yes the link is kinda article and the script itself. > I recommend using referential integrity I hope you are not confusing "on delete cascade" feature in the context of referential integrity. Referential Integrity: NICE On Delete Cascade: BAD (VERY BAD actually)

          P C 2 Replies Last reply
          0
          • J jujiro

            I was going to curse you out but then saw that you are a legend at The Code Project, so I won't. > Write an article: Yes the link is kinda article and the script itself. > I recommend using referential integrity I hope you are not confusing "on delete cascade" feature in the context of referential integrity. Referential Integrity: NICE On Delete Cascade: BAD (VERY BAD actually)

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            jujiro wrote:

            "on delete cascade"

            No, I use that very seldom and only when the data is transient anyway.

            1 Reply Last reply
            0
            • L Lost User

              jujiro wrote:

              Deletion of a row at a top level table can become a project very quickly due the child tables dependencies, which can run several levels deep.

              "Cascading delete". Most modern databases do.

              Bastard Programmer from Hell :suss:

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              Yeah and most experienced devs DON'T use it. I do not recall ever using cascade delete. I do recall chastisiing a junior dev for trashing the database using cascading delete. Oops just does not cut it!

              Never underestimate the power of human stupidity RAH

              L 1 Reply Last reply
              0
              • J jujiro

                If you are fanatic about normalization, I am sure you know the pains associated with it. Deletion of a row at a top level table can become a project very quickly due the child tables dependencies, which can run several levels deep. I have a script to do that. Please feel free to download and share.

                M Offline
                M Offline
                Mycroft Holmes
                wrote on last edited by
                #7

                If an article is too much then a tip/trick requires less commitment. If you can't keep track of your data structure during development then there is something lacking in your methods. Referential integrity via FKs usually meets most of the requirements!

                Never underestimate the power of human stupidity RAH

                J 1 Reply Last reply
                0
                • M Mycroft Holmes

                  Yeah and most experienced devs DON'T use it. I do not recall ever using cascade delete. I do recall chastisiing a junior dev for trashing the database using cascading delete. Oops just does not cut it!

                  Never underestimate the power of human stupidity RAH

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Mycroft Holmes wrote:

                  Yeah and most experienced devs DON'T use it.

                  They rather write queries to check whether there are child-rows, and delete them manually. I understand that people don't use what bites them - about the same brilliant idea as keeping every field a VARCHAR. It's standard functionality of the database, and it's less error-prone than coding it manually. I bet you're glad that I'm not allowed near your systems? :-D

                  Bastard Programmer from Hell :suss:

                  M 1 Reply Last reply
                  0
                  • M Mycroft Holmes

                    If an article is too much then a tip/trick requires less commitment. If you can't keep track of your data structure during development then there is something lacking in your methods. Referential integrity via FKs usually meets most of the requirements!

                    Never underestimate the power of human stupidity RAH

                    J Offline
                    J Offline
                    jujiro
                    wrote on last edited by
                    #9

                    >> If an article is too much then a tip/trick requires less commitment. I don't understand what you mean by that. Anyway, the reason why I developed the script is to see how deep the rabbit hole is. Yes, I can use any reverse engineering ERD tool to see that (Visio is my favorite.) If you have been around as long as I have and have worked on projects where no one really knew the entire system/database, you have to rely on quick and dirty tools like my script to find your way. Visio may or may not be there at your disposal. I really do not understand why people are making smart ass comments about how they do things. Col. Jessep (A few good men) said, "I have neither the time nor the inclination to explain myself to a man who rises and sleeps under the blanket of the very freedom I provide, then questions the manner in which I provide it! I'd rather you just said thank you and went on your way." :)

                    M 1 Reply Last reply
                    0
                    • J jujiro

                      I was going to curse you out but then saw that you are a legend at The Code Project, so I won't. > Write an article: Yes the link is kinda article and the script itself. > I recommend using referential integrity I hope you are not confusing "on delete cascade" feature in the context of referential integrity. Referential Integrity: NICE On Delete Cascade: BAD (VERY BAD actually)

                      C Offline
                      C Offline
                      Chris Meech
                      wrote on last edited by
                      #10

                      jujiro wrote:

                      On Delete Cascade: BAD (VERY BAD actually)

                      I use DELETE and DELETE CASCADE where the model requires me to do so. I find it good practice to limit the number of RI keys I'll define on a table so that I don't get into messes where all for the sake of normalization, someone has defined a row with a couple of dozen RI keys in it. To me that's just asking for a coding nightmare. :)

                      Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

                      1 Reply Last reply
                      0
                      • J jujiro

                        >> If an article is too much then a tip/trick requires less commitment. I don't understand what you mean by that. Anyway, the reason why I developed the script is to see how deep the rabbit hole is. Yes, I can use any reverse engineering ERD tool to see that (Visio is my favorite.) If you have been around as long as I have and have worked on projects where no one really knew the entire system/database, you have to rely on quick and dirty tools like my script to find your way. Visio may or may not be there at your disposal. I really do not understand why people are making smart ass comments about how they do things. Col. Jessep (A few good men) said, "I have neither the time nor the inclination to explain myself to a man who rises and sleeps under the blanket of the very freedom I provide, then questions the manner in which I provide it! I'd rather you just said thank you and went on your way." :)

                        M Offline
                        M Offline
                        Mycroft Holmes
                        wrote on last edited by
                        #11

                        jujiro wrote:

                        you have to rely on quick and dirty tools like my script to find your way.

                        This shows there is something wrong with the environment, if you are going in having to build cascading deletes with no reference to the data structure then it is wrong. Not that we have not all had to do it but in a reasonable application you should not have to. I did not even look at your script/solution, my point was that the way you are approaching it is wrong, this thread will dissapear into the pits fairly rapidly, writing an article will make your contribution more useful, but even a tip/trick will have a more lasting usefulness than a link in a forum post.

                        Never underestimate the power of human stupidity RAH

                        J 1 Reply Last reply
                        0
                        • L Lost User

                          Mycroft Holmes wrote:

                          Yeah and most experienced devs DON'T use it.

                          They rather write queries to check whether there are child-rows, and delete them manually. I understand that people don't use what bites them - about the same brilliant idea as keeping every field a VARCHAR. It's standard functionality of the database, and it's less error-prone than coding it manually. I bet you're glad that I'm not allowed near your systems? :-D

                          Bastard Programmer from Hell :suss:

                          M Offline
                          M Offline
                          Mycroft Holmes
                          wrote on last edited by
                          #12

                          Eddy Vluggen wrote:

                          I understand that people don't use what bites them

                          You may well be right there, the idea of cascading deletes just makes my toes curl.

                          Eddy Vluggen wrote:

                          I bet you're glad that I'm not allowed near your systems

                          You are most certainly right there, I could see endless discussions where each tries to justify their OPOV - fruitlessly.

                          Never underestimate the power of human stupidity RAH

                          1 Reply Last reply
                          0
                          • M Mycroft Holmes

                            jujiro wrote:

                            you have to rely on quick and dirty tools like my script to find your way.

                            This shows there is something wrong with the environment, if you are going in having to build cascading deletes with no reference to the data structure then it is wrong. Not that we have not all had to do it but in a reasonable application you should not have to. I did not even look at your script/solution, my point was that the way you are approaching it is wrong, this thread will dissapear into the pits fairly rapidly, writing an article will make your contribution more useful, but even a tip/trick will have a more lasting usefulness than a link in a forum post.

                            Never underestimate the power of human stupidity RAH

                            J Offline
                            J Offline
                            jujiro
                            wrote on last edited by
                            #13

                            My point in the message to you was that people started writing comments without even clicking on the link. You click on the link you get some more information, may be not a whole lot of explanation, but information it is. Now, about my approach: There could be myriad of reasons why you would want to know the relational linkages. May be you, you were doing a data cleanup, which meant deleting the parent rows, and keeping the child rows by making the foreign key column null, or may even delete cascading, if that is what was needed as a part of the cleanup process. So, unless you know the context, you can say an emphatic "wrongful approach." Do you get my point?

                            M 1 Reply Last reply
                            0
                            • J jujiro

                              My point in the message to you was that people started writing comments without even clicking on the link. You click on the link you get some more information, may be not a whole lot of explanation, but information it is. Now, about my approach: There could be myriad of reasons why you would want to know the relational linkages. May be you, you were doing a data cleanup, which meant deleting the parent rows, and keeping the child rows by making the foreign key column null, or may even delete cascading, if that is what was needed as a part of the cleanup process. So, unless you know the context, you can say an emphatic "wrongful approach." Do you get my point?

                              M Offline
                              M Offline
                              Mycroft Holmes
                              wrote on last edited by
                              #14

                              jujiro wrote:

                              So, unless you know the context, you can say an emphatic "wrongful approach."

                              No no no not the approach you took with the code, I never even looked at it, the wrong way to PRESENT it here. There are always requirements for hacks and workarounds, I was not dumping on your code, just the way you presented it!

                              Never underestimate the power of human stupidity RAH

                              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