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 8289793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:36:18+00:00 2026-06-08T12:36:18+00:00

My question is about foreign keys. For example, we have table X with X_PK

  • 0

My question is about foreign keys. For example, we have table X with X_PK and tables A, B, C with null A_FK_X and null B_FK_X. Table C doesn’t contain an FK to table X. Table A already had records with A_FK_X initialised, but table B doesn’t.

Is it possible to find all usages of specified X_PK in all tables?

  • 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-06-08T12:36:19+00:00Added an answer on June 8, 2026 at 12:36 pm

    You want to use the information_schema database. Try this code (albeit with oversimplified CREATE TABLE statements):

    CREATE TABLE `X` (
        `X_id` INT NOT NULL AUTO_INCREMENT,
        PRIMARY KEY  (`X_id`)
      );
    
      CREATE TABLE `A` (
        `A_id` INT NOT NULL AUTO_INCREMENT,
        `X_id` INT NULL,
        PRIMARY KEY  (`A_id`),
        CONSTRAINT `A_FK_X` FOREIGN KEY (`X_id`) REFERENCES `X` (`X_id`)
      );
    
    CREATE TABLE `B` (
        `B_id` INT NOT NULL AUTO_INCREMENT,
        `X_id` INT NULL,
        PRIMARY KEY  (`B_id`),
        CONSTRAINT `B_FK_X` FOREIGN KEY (`X_id`) REFERENCES `X` (`X_id`)
      );
    
    CREATE TABLE `C` (
      `C_id` INT NOT NULL AUTO_INCREMENT,
      PRIMARY KEY (`C_id`)
    );
    
    USE information_schema;
    SELECT * FROM KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_NAME = 'X' AND REFERENCED_COLUMN_NAME = 'X_id';
    

    This will return all references to X_id in every database, so you could narrow your search by including a TABLE_SCHEMA:

    SELECT * FROM KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_NAME = 'X' AND REFERENCED_COLUMN_NAME = 'X_id' AND TABLE_SCHEMA='testdbname';
    

    On my system, these return the same output, since I only have one database that includes references to X_id, but the output will vary depending on your database/table structure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a general question regarding table indices on foreign keys in database modeling.
I always get stuck on foreign keys so I have a question about where
I have a question about defining Foreign Key in EF Code First Fluent API.
I have project which contain 4 tables among these shedule table Session column i
We have a table(say T1) that is referenced by about 16 other tables with
I have a question about sql relation conception. I have a simple example. A
I have a question about a ForeignKey reference problem with django. This is a
Question about GridView sorting in VB.NET: I have a GridView with AutoGenerateColumns = True
Question about assignments and variables (* For example *) SP = SparseArray[{},5] or SP
Got a question about Entity Framework and MyIsam tables. My production database consists of

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.