View All Tables, user tables, column names, primary keys, and foreign keys in Oracle

Source: Internet
Author: User
View all tables in Oracle:
Select * From TAB/dba_tables/dba_objects/CAT;
View the table created by the user:
Select table_name from user_tables; // The table of the current user
Select table_name from all_tables; // tables of all users
Select table_name from dba_tables; // includes the system table
Select * From user_indexes // all user table indexes can be queried.
Query all user tables in all_tables
Primary Key name and foreign key in all_constraints
Index in all_indexes
However, the primary key will also become an index, so the primary key will also be in all_indexes.
You can DESC the required fields to view these views. If you log on to the DBA, you can change all to DBA.
1. Search for all indexes of a table (including index names, types, and columns ):
Select T. *, I. index_type from user_ind_columns T, user_indexes I where T. index_name = I. index_name and T. table_name = I. table_name and T. table_name = table to be queried
2. Search for the table's primary key (including names and columns ):
Select cu. * From user_cons_columns Cu, user_constraints au where cu. constraint_name = Au. constraint_name and AU. constraint_type = "P" and AU. table_name = table to be queried
3. query the uniqueness constraints of a table (including names and columns ):
Select column_name from user_cons_columns Cu, user_constraints au where cu. constraint_name = Au. constraint_name and AU. constraint_type = "u" and AU. table_name = table to be queried
4. Search for the table's foreign key (including the name, referenced table name, and corresponding key name. The following is a multi-step query ):
Select * From user_constraints c Where C. constraint_type = "R" and C. table_name = table to be queried
Query the names of Columns with foreign key constraints:
Select * From user_cons_columns Cl where Cl. constraint_name = foreign key name
Query the column name of the key of the referenced table:
Select * From user_cons_columns Cl where Cl. constraint_name = foreign key reference table key name
5. query all the columns and their attributes of the table.
Select T. *, C. Comments from user_tab_columns T, user_col_comments C where T. table_name = C. table_name and T. column_name = C. column_name and T. table_name = table to be queried
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.