Query below lists all primary keys constraints (PK) in the database with their columns (one row per column).
See also: list of all primary keys (one row per PK).
select table_schema, table_name, constraint_name, ordinal_position as pos, column_name, is_enabled from v_catalog.primary_keys order by table_schema, table_name, ordinal_position;
- table_schema - PK schema name
- table_name - PK table name
- constraint_name - PK constraint name
- pos - index of column in table (1, 2, ...). 2 or higher means key is composite (contains more than one column)
- column_name - PK column name
- is_enabled - indicate if primary key constraint is enabled or not
- One row represents one primary key column
- Scope of rows: columns of all PK constraints in a database
- Ordered by table schema, table name, column position
You could also get this
Get this interactive HTML data dictionary in minutes with Dataedo.