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.
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.