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. Other Discussions
  3. The Weird and The Wonderful
  4. What use are foreign keys anyway?

What use are foreign keys anyway?

Scheduled Pinned Locked Moved The Weird and The Wonderful
databasesql-serversysadminquestion
60 Posts 37 Posters 2 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.
  • R Offline
    R Offline
    Rob Grainger
    wrote on last edited by
    #1

    A colleague today asked me to show him the database structure for an application I wrote a couple of years ago, for maintenance purposes. I directed him to the database diagram I had helpfully created in SQL Server. Sadly, upon opening it, it became apparent that someone had for some unknown reason decided to remove all the relationships between all the tables, for no obvious reason. I despair sometimes.

    "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

    M R T Sander RosselS C 21 Replies Last reply
    0
    • R Rob Grainger

      A colleague today asked me to show him the database structure for an application I wrote a couple of years ago, for maintenance purposes. I directed him to the database diagram I had helpfully created in SQL Server. Sadly, upon opening it, it became apparent that someone had for some unknown reason decided to remove all the relationships between all the tables, for no obvious reason. I despair sometimes.

      "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

      M Offline
      M Offline
      megaadam
      wrote on last edited by
      #2

      Parallel relationships can produce unspecified behaviour. Especially if the other one finds out.

      ... such stuff as dreams are made on

      1 Reply Last reply
      0
      • R Rob Grainger

        A colleague today asked me to show him the database structure for an application I wrote a couple of years ago, for maintenance purposes. I directed him to the database diagram I had helpfully created in SQL Server. Sadly, upon opening it, it became apparent that someone had for some unknown reason decided to remove all the relationships between all the tables, for no obvious reason. I despair sometimes.

        "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

        R Offline
        R Offline
        RickZeeland
        wrote on last edited by
        #3

        Guess that guy couldn't relate :-\

        1 Reply Last reply
        0
        • R Rob Grainger

          A colleague today asked me to show him the database structure for an application I wrote a couple of years ago, for maintenance purposes. I directed him to the database diagram I had helpfully created in SQL Server. Sadly, upon opening it, it became apparent that someone had for some unknown reason decided to remove all the relationships between all the tables, for no obvious reason. I despair sometimes.

          "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

          T Offline
          T Offline
          Tim Carmichael
          wrote on last edited by
          #4

          And therein lies the value of forced auditing, saved outside the environment. Perhaps a block-chain on changes is needed... unless of course, the change is done from the 'sa' account and multiple people have access to the password.

          1 Reply Last reply
          0
          • R Rob Grainger

            A colleague today asked me to show him the database structure for an application I wrote a couple of years ago, for maintenance purposes. I directed him to the database diagram I had helpfully created in SQL Server. Sadly, upon opening it, it became apparent that someone had for some unknown reason decided to remove all the relationships between all the tables, for no obvious reason. I despair sometimes.

            "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

            Sander RosselS Offline
            Sander RosselS Offline
            Sander Rossel
            wrote on last edited by
            #5

            I've experienced something like that once. For no reason, quite a few FK's had disappeared... I'm pretty certain no one on the team did it because we all knew the value of FK's. To this day I've seen it once and still can't explain it. My guess is that some external tool (comparer? EF? modeller?) removed them for some reason.

            Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

            J A O 4 Replies Last reply
            0
            • Sander RosselS Sander Rossel

              I've experienced something like that once. For no reason, quite a few FK's had disappeared... I'm pretty certain no one on the team did it because we all knew the value of FK's. To this day I've seen it once and still can't explain it. My guess is that some external tool (comparer? EF? modeller?) removed them for some reason.

              Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

              J Offline
              J Offline
              Jorgen Andersson
              wrote on last edited by
              #6

              Sander Rossel wrote:

              I'm pretty certain no one on the team did it because we all knew the value of FK's.

              Since "everyone knows it", no one would admit not knowing.

              Wrong is evil and must be defeated. - Jeff Ello

              1 Reply Last reply
              0
              • R Rob Grainger

                A colleague today asked me to show him the database structure for an application I wrote a couple of years ago, for maintenance purposes. I directed him to the database diagram I had helpfully created in SQL Server. Sadly, upon opening it, it became apparent that someone had for some unknown reason decided to remove all the relationships between all the tables, for no obvious reason. I despair sometimes.

                "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                C Offline
                C Offline
                CodeWraith
                wrote on last edited by
                #7

                Rob Grainger wrote:

                for some unknown reason

                It's always the same reason: Some dimwit tries to insert or delete something and bounces off these foreign key constraints. Instead of adapting the application logic to take the constraints into account, the harebrain throws the constraints (and the database's integrity) out the window. And what will they say when you ask them which part of 'referential integrity' they did not understand? (Offended whine): "But it works (*)!" (*) In there limited little world that means that the error message is gone, nothing more.

                I have lived with several Zen masters - all of them were cats.

                R B 2 Replies Last reply
                0
                • C CodeWraith

                  Rob Grainger wrote:

                  for some unknown reason

                  It's always the same reason: Some dimwit tries to insert or delete something and bounces off these foreign key constraints. Instead of adapting the application logic to take the constraints into account, the harebrain throws the constraints (and the database's integrity) out the window. And what will they say when you ask them which part of 'referential integrity' they did not understand? (Offended whine): "But it works (*)!" (*) In there limited little world that means that the error message is gone, nothing more.

                  I have lived with several Zen masters - all of them were cats.

                  R Offline
                  R Offline
                  RJOberg
                  wrote on last edited by
                  #8

                  CodeWraith wrote:

                  Some dimwit tries to insert or delete something and bounces off these foreign key constraints. Instead of adapting the application logic to take the constraints into account, the harebrain throws the constraints (and the database's integrity) out the window.

                  First job out of college, I was that dimwit Jr Developer. We needed to delete a few items and add a few new ones. You guessed it, I ran into the constraints. So I asked the Sr. Dev, he said to drop the keys, add and remove the items, then re-add the keys. Being a good student, I followed his advice. At least I was smart enough to use the automated generate Drop/Add script functionality in SQL so I didn't screw it up THAT much. Learning through mistakes.

                  C R 2 Replies Last reply
                  0
                  • R RJOberg

                    CodeWraith wrote:

                    Some dimwit tries to insert or delete something and bounces off these foreign key constraints. Instead of adapting the application logic to take the constraints into account, the harebrain throws the constraints (and the database's integrity) out the window.

                    First job out of college, I was that dimwit Jr Developer. We needed to delete a few items and add a few new ones. You guessed it, I ran into the constraints. So I asked the Sr. Dev, he said to drop the keys, add and remove the items, then re-add the keys. Being a good student, I followed his advice. At least I was smart enough to use the automated generate Drop/Add script functionality in SQL so I didn't screw it up THAT much. Learning through mistakes.

                    C Offline
                    C Offline
                    CodeWraith
                    wrote on last edited by
                    #9

                    I can certainly forgive a junior, but also would make him repair the database and then scrub the courtyard with a toothbrush. Some old habits die hard. The real horror are those who never learn and do this whenever they feel like it.

                    I have lived with several Zen masters - all of them were cats.

                    N 1 Reply Last reply
                    0
                    • R Rob Grainger

                      A colleague today asked me to show him the database structure for an application I wrote a couple of years ago, for maintenance purposes. I directed him to the database diagram I had helpfully created in SQL Server. Sadly, upon opening it, it became apparent that someone had for some unknown reason decided to remove all the relationships between all the tables, for no obvious reason. I despair sometimes.

                      "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                      T Offline
                      T Offline
                      txmrm
                      wrote on last edited by
                      #10

                      Trust me, it could be worse. My company sells a very large application using a SQL Server database. There are over 1500 tables in the database. You can count the number of defined FK relations on one hand and I suspect those were added by mistake. I have brought this up several times and it's always the same answer. We don't need no stinking FK relations in the database - the application code handles all of that. Of course, the poor support people constantly have to deal with application issues caused by orphaned data, etc.

                      R D D P 4 Replies Last reply
                      0
                      • R Rob Grainger

                        A colleague today asked me to show him the database structure for an application I wrote a couple of years ago, for maintenance purposes. I directed him to the database diagram I had helpfully created in SQL Server. Sadly, upon opening it, it became apparent that someone had for some unknown reason decided to remove all the relationships between all the tables, for no obvious reason. I despair sometimes.

                        "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                        R Offline
                        R Offline
                        raddevus
                        wrote on last edited by
                        #11

                        Are you saying that they removed a column from an associated table? (Very bad) Or are you saying they removed the foreign key constraint from the associated table's matching column? (not as bad). The relationships are still there even without the strict foreign key constraint. They are not just a bit more philosophical. :rolleyes: The discipline to insure they stay in sync, now just rests with the people and not the system. Power to the people!! :laugh:

                        1 Reply Last reply
                        0
                        • T txmrm

                          Trust me, it could be worse. My company sells a very large application using a SQL Server database. There are over 1500 tables in the database. You can count the number of defined FK relations on one hand and I suspect those were added by mistake. I have brought this up several times and it's always the same answer. We don't need no stinking FK relations in the database - the application code handles all of that. Of course, the poor support people constantly have to deal with application issues caused by orphaned data, etc.

                          R Offline
                          R Offline
                          Rob Grainger
                          wrote on last edited by
                          #12

                          Believe it or not, when I first started here, the majority of tables didn't even have primary keys, let alone foreign keys. It's been getting incrementally better since then.

                          "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                          1 Reply Last reply
                          0
                          • R Rob Grainger

                            A colleague today asked me to show him the database structure for an application I wrote a couple of years ago, for maintenance purposes. I directed him to the database diagram I had helpfully created in SQL Server. Sadly, upon opening it, it became apparent that someone had for some unknown reason decided to remove all the relationships between all the tables, for no obvious reason. I despair sometimes.

                            "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

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

                            Rob Grainger wrote:

                            Sadly, upon opening it, it became apparent that someone had for some unknown reason decided to remove all the relationships between all the tables, for no obvious reason.

                            "This is an unsupported version. You're elephanted due to stupidity. Do not pass 'start' and jump of the nearest building to hide your tracks." I've become good at descriptive exception-texts :rolleyes:

                            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                            1 Reply Last reply
                            0
                            • R Rob Grainger

                              A colleague today asked me to show him the database structure for an application I wrote a couple of years ago, for maintenance purposes. I directed him to the database diagram I had helpfully created in SQL Server. Sadly, upon opening it, it became apparent that someone had for some unknown reason decided to remove all the relationships between all the tables, for no obvious reason. I despair sometimes.

                              "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                              R Offline
                              R Offline
                              Ravi Sant
                              wrote on last edited by
                              #14

                              That someone could have been fan of No SQL world and sees relationship as spaghetti code

                              // ♫ 99 little bugs in the code, // 99 bugs in the code // We fix a bug, compile it again // 101 little bugs in the code ♫

                              Tell your manager, while you code: "good, cheap or fast: pick two. "

                              N 1 Reply Last reply
                              0
                              • R Rob Grainger

                                A colleague today asked me to show him the database structure for an application I wrote a couple of years ago, for maintenance purposes. I directed him to the database diagram I had helpfully created in SQL Server. Sadly, upon opening it, it became apparent that someone had for some unknown reason decided to remove all the relationships between all the tables, for no obvious reason. I despair sometimes.

                                "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                                W Offline
                                W Offline
                                wout de zeeuw
                                wrote on last edited by
                                #15

                                On my own projects I always script my datatabase into an SQL file and save it into subversion along with my source code. Any changes can be found in the svn log afterwards, works great.

                                Wout

                                1 Reply Last reply
                                0
                                • R Rob Grainger

                                  A colleague today asked me to show him the database structure for an application I wrote a couple of years ago, for maintenance purposes. I directed him to the database diagram I had helpfully created in SQL Server. Sadly, upon opening it, it became apparent that someone had for some unknown reason decided to remove all the relationships between all the tables, for no obvious reason. I despair sometimes.

                                  "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

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

                                  Got a drawer full of them.

                                  Peter Wasser "The whole problem with the world is that fools and fanatics are always so certain of themselves, and wiser people so full of doubts." - Bertrand Russell

                                  1 Reply Last reply
                                  0
                                  • T txmrm

                                    Trust me, it could be worse. My company sells a very large application using a SQL Server database. There are over 1500 tables in the database. You can count the number of defined FK relations on one hand and I suspect those were added by mistake. I have brought this up several times and it's always the same answer. We don't need no stinking FK relations in the database - the application code handles all of that. Of course, the poor support people constantly have to deal with application issues caused by orphaned data, etc.

                                    D Offline
                                    D Offline
                                    David ONeil
                                    wrote on last edited by
                                    #17

                                    txmrm wrote:

                                    There are over 1500 tables in the database.

                                    Let me guess. They are named like "AGC1", "RCV32", etc? I worked with business logic once, and got to look at the tables behind BPCS. F me, what a clusterF. I once created an engineering change notice database which tracked changes to BOMs, and said which notice was on which person's desk, when they were due, which ones were associated with which project, etc. With the BOM table, there were only 32 tables in total. And some of them were just work tables which were repopulated via queries. 1500? Sounds like terribly engineered insanity!

                                    The forgotten roots of science | C++ Programming | DWinLib

                                    1 Reply Last reply
                                    0
                                    • R Ravi Sant

                                      That someone could have been fan of No SQL world and sees relationship as spaghetti code

                                      // ♫ 99 little bugs in the code, // 99 bugs in the code // We fix a bug, compile it again // 101 little bugs in the code ♫

                                      Tell your manager, while you code: "good, cheap or fast: pick two. "

                                      N Offline
                                      N Offline
                                      Nathan Minier
                                      wrote on last edited by
                                      #18

                                      Or as a tight-coupling to a specific storage paradigm.

                                      "There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli

                                      1 Reply Last reply
                                      0
                                      • C CodeWraith

                                        I can certainly forgive a junior, but also would make him repair the database and then scrub the courtyard with a toothbrush. Some old habits die hard. The real horror are those who never learn and do this whenever they feel like it.

                                        I have lived with several Zen masters - all of them were cats.

                                        N Offline
                                        N Offline
                                        Nelek
                                        wrote on last edited by
                                        #19

                                        In this case I would say the Sr. Dev should repair it. Since the Jr Dev was following instructions. Another thing would be if the Jr. Dev. just did it because he/she is smarter than the Sr. Dev.

                                        CodeWraith wrote:

                                        Some old habits die hard.

                                        It is like smoking, the best... not to start ;)

                                        M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                                        C 1 Reply Last reply
                                        0
                                        • N Nelek

                                          In this case I would say the Sr. Dev should repair it. Since the Jr Dev was following instructions. Another thing would be if the Jr. Dev. just did it because he/she is smarter than the Sr. Dev.

                                          CodeWraith wrote:

                                          Some old habits die hard.

                                          It is like smoking, the best... not to start ;)

                                          M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                                          C Offline
                                          C Offline
                                          CodeWraith
                                          wrote on last edited by
                                          #20

                                          Now that you remind me... I forgot to insist on the first and the last words when anyone addresses me should be 'sir'. Another one of those old habits.

                                          I have lived with several Zen masters - all of them were cats.

                                          N 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