Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6043275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:52:54+00:00 2026-05-23T06:52:54+00:00

I have 3 different sql environments which are similar but not same. I have

  • 0

I have 3 different sql environments which are similar but not same. I have a column “CLMID” used in different tables. Most of them are linked with the foreign key mapping. But some tables are corrupted so do not have the foreign key mapping done right. I now need to update a data into this column in all tables. So I need a query which will find for me the list of tables that are having proper mapping, so that if I update the parent they update the child by them self. I also need to find the constraint the other way where, only if I update the child I can update the parent table.

Please note that I need to get this list without doing any update or insert operations as Its a critical database. Please help me with the query. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:52:55+00:00Added an answer on May 23, 2026 at 6:52 am

    Every SQL product has some way to query the database for schema data, including keys. Learning to use the Information_Schema is best IMHO because it is a standard across most platforms (as I recall Oracle does not implement it).

    SQL Server probably has some easier queries with its own catalogs, but the following somewhat hairy query gives you exactly what you want and is the most cross-platform you can get.

    SELECT 
        FK.TABLE_NAME as child_table, 
        CU.COLUMN_NAME as child_column, 
        PK.TABLE_NAME  as parent_table, 
        PT.COLUMN_NAME as parent_column,
        C.CONSTRAINT_NAME 
    FROM 
    INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C 
    INNER JOIN 
    INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK 
        ON C.CONSTRAINT_NAME = FK.CONSTRAINT_NAME 
    INNER JOIN 
    INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK 
        ON C.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAME 
    INNER JOIN 
    INFORMATION_SCHEMA.KEY_COLUMN_USAGE CU 
        ON C.CONSTRAINT_NAME = CU.CONSTRAINT_NAME 
    INNER JOIN 
    ( 
        SELECT 
            i1.TABLE_NAME, i2.COLUMN_NAME 
        FROM 
            INFORMATION_SCHEMA.TABLE_CONSTRAINTS i1 
            INNER JOIN 
            INFORMATION_SCHEMA.KEY_COLUMN_USAGE i2 
            ON i1.CONSTRAINT_NAME = i2.CONSTRAINT_NAME 
            WHERE i1.CONSTRAINT_TYPE = 'PRIMARY KEY' 
    ) PT 
    ON PT.TABLE_NAME = PK.TABLE_NAME 
    ORDER BY 
    1,2,3,4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a LINQ to SQL DataContext that queries four different tables. But I
I have nine different databases representing companies, all on the same SQL server 2008
I have all my tables, views, triggers in different files (Table1.sql, Table2.sql, View1.sql,...), and
I have a SQL Server table which has 625 columns created with different datatypes
We have 2 web-servers which are theoretically identical, but are producing different results when
I am using SQL Server 2008 R2. I have created two different databases Master
Basically I have 2 SQL queries from 2 different databases and I am trying
I have trouble accessing filestream via SqlFileStream. Sql server and IIS7 are on different
Environment: SQL, LINQ, C# I have 2 WinForms running on different computers. They all
I have a situation in which I have taken a backup(sql scripyts containing the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.