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. How to get reference information between parent and child tables (MS SQL Server/MSAccess)? [modified]

How to get reference information between parent and child tables (MS SQL Server/MSAccess)? [modified]

Scheduled Pinned Locked Moved Database
databasetutorialsql-serversysadminquestion
5 Posts 4 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.
  • P Offline
    P Offline
    priyamtheone
    wrote on last edited by
    #1

    Is it possible to get information about whether a child table has reference to a parent table through a certain record? For example, tblParent has a record whose primary key value is 5. I want to know whether tblChild_A, tblChild_B and tblChild_C have one or more records in them where the foreign key value is 5. Well it's definitely possible by querying each of the child tables individually but I want to know whether there's any system query or stored procedure or whatever that produces a tabular output from all those tables together. If it's possible in MS SQL Server then please also inform what's its counterpart in MS Access. Regards.

    modified on Tuesday, June 14, 2011 3:16 AM

    _ S M 3 Replies Last reply
    0
    • P priyamtheone

      Is it possible to get information about whether a child table has reference to a parent table through a certain record? For example, tblParent has a record whose primary key value is 5. I want to know whether tblChild_A, tblChild_B and tblChild_C have one or more records in them where the foreign key value is 5. Well it's definitely possible by querying each of the child tables individually but I want to know whether there's any system query or stored procedure or whatever that produces a tabular output from all those tables together. If it's possible in MS SQL Server then please also inform what's its counterpart in MS Access. Regards.

      modified on Tuesday, June 14, 2011 3:16 AM

      _ Offline
      _ Offline
      _Damian S_
      wrote on last edited by
      #2

      It's a very simple query to return how many records in a child table match a parent's ID, however, you haven't really made it clear what you want to achieve. How many child tables do you have? Why don't you want to query them individually?

      Silence is golden... but duct tape is silver!! Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!

      P 1 Reply Last reply
      0
      • _ _Damian S_

        It's a very simple query to return how many records in a child table match a parent's ID, however, you haven't really made it clear what you want to achieve. How many child tables do you have? Why don't you want to query them individually?

        Silence is golden... but duct tape is silver!! Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!

        P Offline
        P Offline
        priyamtheone
        wrote on last edited by
        #3

        Well as I said, if possible, I want to get a tabular output showing which tables are related to a certain primary table and the related data in them all-together. Please refer to the second paragraph in my OP. Feel free to ask if I'm still not clear.

        1 Reply Last reply
        0
        • P priyamtheone

          Is it possible to get information about whether a child table has reference to a parent table through a certain record? For example, tblParent has a record whose primary key value is 5. I want to know whether tblChild_A, tblChild_B and tblChild_C have one or more records in them where the foreign key value is 5. Well it's definitely possible by querying each of the child tables individually but I want to know whether there's any system query or stored procedure or whatever that produces a tabular output from all those tables together. If it's possible in MS SQL Server then please also inform what's its counterpart in MS Access. Regards.

          modified on Tuesday, June 14, 2011 3:16 AM

          S Offline
          S Offline
          Simon_Whale
          wrote on last edited by
          #4

          Have a read through this article on sp_help[^] There is a section in the article that shows the tables a given table references.

          Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

          1 Reply Last reply
          0
          • P priyamtheone

            Is it possible to get information about whether a child table has reference to a parent table through a certain record? For example, tblParent has a record whose primary key value is 5. I want to know whether tblChild_A, tblChild_B and tblChild_C have one or more records in them where the foreign key value is 5. Well it's definitely possible by querying each of the child tables individually but I want to know whether there's any system query or stored procedure or whatever that produces a tabular output from all those tables together. If it's possible in MS SQL Server then please also inform what's its counterpart in MS Access. Regards.

            modified on Tuesday, June 14, 2011 3:16 AM

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

            While there are system views which will identify the FKs between tables this is not a system issues but a data problem. You will need to craft a query that get the data you want the way you want it. There is no 'system' query/function etc that will service this requirement. It is a fairly simple excercise using either sub queries or left joins depending on the required output.

            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