For a given table 'foo', I need a query to generate a set of tables that have foreign keys that point to foo. I'm using Oracle 10G.
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- php PDO::FETCH_ASSOC doesnt detect select after ba
- Bulk update SQL Server C#
This should work (or something close):
The following statement should give the children and all of their descendents. I have tested it on an Oracle 10 database.
I know it's kinda late to answer but let me answer anyway, some of the answers above are quite complicated hence here is a much simpler take.
Download the Oracle Reference Guide for 10G which explains the data dictionary tables.
The answers above are good but check out the other tables which may relate to constraints.
Finally, get a tool like Toad or SQL Developer which allows you to browse this stuff in a UI, you need to learn to use the tables but you should use a UI also.
Here's how to take Mike's query one step further to get the column names from the constraint names:
link to Oracle Database Online Documentation
You may want to explore the Data Dictionary views. They have the prefixes:
sample:
Continuing Mike's example, you may want to generate scripts to enable/disable the constraints. I only modified the 'select' in the first row.