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?
You want to use the
information_schemadatabase. Try this code (albeit with oversimplifiedCREATE TABLEstatements):This will return all references to
X_idin every database, so you could narrow your search by including aTABLE_SCHEMA: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.