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 3 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 realJSOP

    Be careful of the "Script To..." option. Pay Attention to What "Script...To" Generates[^]

    ".45 ACP - because shooting twice is just silly" - JSOP, 2010
    -----
    You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
    -----
    When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

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

    Thank you for the heads up. Haven't run into that before, at least that I've ever noticed, but will start to check from now on. I wonder what caused the line-breaks. To the best of my recollection it has always generated one line per statement, no matter the length of said line.

    R 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
      TheGreatAndPowerfulOz
      wrote on last edited by
      #51

      Maybe you did it one night after taking some Adderol... ;P

      #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

      1 Reply 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.

        B Offline
        B Offline
        Bohdan Stupak
        wrote on last edited by
        #52

        Sad but true. I used to support such db at the start of my career

        1 Reply Last reply
        0
        • R RJOberg

          Thank you for the heads up. Haven't run into that before, at least that I've ever noticed, but will start to check from now on. I wonder what caused the line-breaks. To the best of my recollection it has always generated one line per statement, no matter the length of said line.

          R Offline
          R Offline
          realJSOP
          wrote on last edited by
          #53

          Yeah, that was the most weird thing I've seen in sql.

          ".45 ACP - because shooting twice is just silly" - JSOP, 2010
          -----
          You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
          -----
          When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

          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.

            H Offline
            H Offline
            HarvestMoon0000
            wrote on last edited by
            #54

            was probably having issues removing a row ! HAAAAAA !

            1 Reply Last reply
            0
            • R realJSOP

              Be careful of the "Script To..." option. Pay Attention to What "Script...To" Generates[^]

              ".45 ACP - because shooting twice is just silly" - JSOP, 2010
              -----
              You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
              -----
              When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

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

              Last year I finally got around to writing a utility that uses SMO with exactly the settings I insist on for generating scripts. Things are so much more stable now.

              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.

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

                txmrm wrote:

                with application issues caused by orphaned data

                Then they're not testing properly. A production app should not rely on constraints.

                1 Reply 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

                  O Offline
                  O Offline
                  Out of Memory
                  wrote on last edited by
                  #57

                  I've seen this too, and know the reason. It's not a good reason, but it's a reason. I'd designed and built a database with full referential integrity. A team of programmers started to build a system around it. Every time their code violated the rules, guess what? An exception was triggered! As intended. Imagine that. It came to time to roll out the project. This meant deploying a fresh copy of the database to a production server. I used the same scripts that I'd written to deploy the development copy. This resulted in a herd of coders arriving at my desk, all red in the face, and demanding that I use the copy on the development machine. It seems that between them, their understanding of error handling consisted of "on error goto", and they'd been so overwhelmed by the exceptions that the RI in the database caused, they'd removed all of it from the database. Seems my idiot boss saw no harm in giving them admin rights on the database server. Thankfully, he took my side when I explained to him why the project was going to be delayed! So, if you're surrounded by idiots, then there's a reason why the RI was removed. It's not a good reason, but it's certainly a reason. Namely, you're surrounded by idiots.

                  Sander RosselS 1 Reply Last reply
                  0
                  • O Out of Memory

                    I've seen this too, and know the reason. It's not a good reason, but it's a reason. I'd designed and built a database with full referential integrity. A team of programmers started to build a system around it. Every time their code violated the rules, guess what? An exception was triggered! As intended. Imagine that. It came to time to roll out the project. This meant deploying a fresh copy of the database to a production server. I used the same scripts that I'd written to deploy the development copy. This resulted in a herd of coders arriving at my desk, all red in the face, and demanding that I use the copy on the development machine. It seems that between them, their understanding of error handling consisted of "on error goto", and they'd been so overwhelmed by the exceptions that the RI in the database caused, they'd removed all of it from the database. Seems my idiot boss saw no harm in giving them admin rights on the database server. Thankfully, he took my side when I explained to him why the project was going to be delayed! So, if you're surrounded by idiots, then there's a reason why the RI was removed. It's not a good reason, but it's certainly a reason. Namely, you're surrounded by idiots.

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

                    How could such software go into production? It's not correct by definition :wtf: No (acceptance) testing?

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

                    S 1 Reply Last reply
                    0
                    • Sander RosselS Sander Rossel

                      How could such software go into production? It's not correct by definition :wtf: No (acceptance) testing?

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

                      S Offline
                      S Offline
                      S Douglas
                      wrote on last edited by
                      #59

                      Sander Rossel wrote:

                      No (acceptance) testing?

                      There is no testing, like testing in production! :)


                      Common sense is admitting there is cause and effect and that you can exert some control over what you understand.

                      1 Reply Last reply
                      0
                      • C CodeWraith

                        That kind of stuff was reserved for basic training or special occasions when you intended to hold a monologue to someone (which then usually ended with 'Dismissed', meaning 'get out of my sight').

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

                        J Offline
                        J Offline
                        jackbrownii
                        wrote on last edited by
                        #60

                        Ah, the good, old high volume one-way discussion.

                        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