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 all reference of a column in a database.

How to get all reference of a column in a database.

Scheduled Pinned Locked Moved Database
databasetutorial
7 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.
  • D Offline
    D Offline
    digvijay dobhal
    wrote on last edited by
    #1

    Dear sir Please explain me how i can get the reference of a primary key colun in a database. what exactly i want to do.... I have a table "[plan]" "PK column is PlanId" how many tables are using this column reference(foregin key reference) in mydatabase, i wana get these tables name. Waiting for your favorable reply. Regards Digvijay

    N U L 3 Replies Last reply
    0
    • D digvijay dobhal

      Dear sir Please explain me how i can get the reference of a primary key colun in a database. what exactly i want to do.... I have a table "[plan]" "PK column is PlanId" how many tables are using this column reference(foregin key reference) in mydatabase, i wana get these tables name. Waiting for your favorable reply. Regards Digvijay

      N Offline
      N Offline
      Nagy Vilmos
      wrote on last edited by
      #2

      There is not an easy answer here, it is down to your database schema. One way I would approach this is to buy a bottle of good scotch and take it to the DBA. Ask the DBA "what tables link to plan using planId?" If he can't help then you'll need to do some mining. First find the candidate field names. Not knowing which DB you are using I can give a generic idea:

      SELECT DISTINCT COLUMN_NAME FROM SYSTEM_COLUMNS

      Here the table SYSTEM_COLUMNS is the system table containing all the column definitions and COLUMN_NAME is the field with the column name. If you know the definition of the field planId you could add it into the query to narrow down the search. Once you have your fields, you can then query to get the tables that contain these fields. It is /relatively/ easy SQL but does need a bit of leg work to read through the results and ensure you have no false positives. If the table and column names do not follow a structure then I am afraid you may well have to use educated guesses.


      Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

      1 Reply Last reply
      0
      • D digvijay dobhal

        Dear sir Please explain me how i can get the reference of a primary key colun in a database. what exactly i want to do.... I have a table "[plan]" "PK column is PlanId" how many tables are using this column reference(foregin key reference) in mydatabase, i wana get these tables name. Waiting for your favorable reply. Regards Digvijay

        U Offline
        U Offline
        UNCRushFan
        wrote on last edited by
        #3

        Could you please tell us what RDBMS you are using? Oracle? MySQL? Microsoft SQL Server? This will help us to better help you with an answer.

        D 1 Reply Last reply
        0
        • U UNCRushFan

          Could you please tell us what RDBMS you are using? Oracle? MySQL? Microsoft SQL Server? This will help us to better help you with an answer.

          D Offline
          D Offline
          digvijay dobhal
          wrote on last edited by
          #4

          Dera Sir, Thanks for your quick response. I'm using SQL server 2008 and SQL server 2008R2

          1 Reply Last reply
          0
          • D digvijay dobhal

            Dear sir Please explain me how i can get the reference of a primary key colun in a database. what exactly i want to do.... I have a table "[plan]" "PK column is PlanId" how many tables are using this column reference(foregin key reference) in mydatabase, i wana get these tables name. Waiting for your favorable reply. Regards Digvijay

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

            Since you mentioned in one of your comments that you are using SQL Server 2008, you can query the sys.foreign_keys table to get the information you want.

            U D 2 Replies Last reply
            0
            • L Lost User

              Since you mentioned in one of your comments that you are using SQL Server 2008, you can query the sys.foreign_keys table to get the information you want.

              U Offline
              U Offline
              UNCRushFan
              wrote on last edited by
              #6

              I second that suggestion. :cool:

              1 Reply Last reply
              0
              • L Lost User

                Since you mentioned in one of your comments that you are using SQL Server 2008, you can query the sys.foreign_keys table to get the information you want.

                D Offline
                D Offline
                digvijay dobhal
                wrote on last edited by
                #7

                Thnks all finally i got.

                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