5. Metadata Queries

Refer to the RDBMS’s documentation for the complete list of catalog or data dictionary tables/views for more details.

Oracle Metadata Tables

Metadata Table
Description

ALL_TABLES

Contains information about all tables accessible to the current user.

ALL_TAB_COLUMNS

Contains information about all columns in all tables accessible to the current user.

ALL_IND_COLUMNS

Contains information about all columns in indexes on all tables accessible to the current user.

ALL_CONSTRAINTS

Contains information about all constraints on tables accessible to the current user.

ALL_CONS_COLUMNS

Contains information about columns that are used in constraints on tables accessible to the current user.

USER_TABLES

Contains information about all tables owned by the current user.

USER_CONSTRAINTS

Contains information about all constraints on tables owned by the current user.

DICTIONARY

Contains descriptions of all dictionary tables and views.

DICT_COLUMNS

Contains information about columns of all dictionary tables and views.

ALL_VIEWS

Shows information about Views to which the user has access, regardless of ownership

USER_ VIEWS

Shows information about Views owned by the current user.

Listing Tables in a Schema

We want to see a list of all the tables we have created in a given schema

-- Oracle
select table_name from all_tables
where owner = 'PRANAY'

-- PostgreSQL, MySQL, and SQL Server 
select table_name from information_schema.tables
where table_schema = 'PRANAY'

Listing a Table’s Columns

We want to list the columns in a table, along with their data types, and their position in the table they are in.

Listing Indexed Columns for a Table

We want to list indexes, their columns, and the column position (if available) in the index for a given table.

Listing Constraints on a Table

We want to list the constraints defined for a table in some schema and the columns they are defined on.

Listing Foreign Keys Without Corresponding Indexes

We want to list tables that have foreign key columns that are not indexed.

Using SQL to Generate SQL

We want to create dynamic SQL statements. We need to accomplish three tasks in particular: count the number of rows in tables, disable foreign key constraints defined on tables, and generate insert scripts from the data in tables.

Describing the Data Dictionary Views in an Oracle Database

Oracle maintain a robust set of data dictionary views and also there are data dictionary views to document the data dictionary views.

Last updated