---
title: "System catalog"
description: "Read schema information from the CoraDB system catalog with SQL: tables, columns, indexes, privileges, partitions and triggers."
url: "https://www.coradb.ai/manual/sql/catalog.html"
markdown_url: "https://www.coradb.ai/manual/markdown/sql/catalog.md"
product: "CoraDB"
version: "1.0"
keywords: "coradb system catalog, information schema, list tables, list columns, list indexes, db_class, db_attribute, db_index, catalog views, catalog classes"
---

# System catalog

The *system catalog* holds the schema of a database: its tables, columns, indexes, users, permissions, partitions, triggers and stored procedures. CoraDB keeps it up to date automatically whenever a DDL statement or a **GRANT** / **REVOKE** runs, and it can be read with ordinary **SELECT** statements.

The catalog has two layers:

- **[System catalog classes](https://www.coradb.ai/manual/sql/catalog_classes.html)** such as `_db_class` and `_db_attribute` store the information, with numeric codes and references between rows. Only **DBA** can read them.
- **[System catalog views](https://www.coradb.ai/manual/sql/catalog_views.html)** such as `db_class` and `db_attribute` show the same information with names and readable values. Every user can read them, and each user sees only the tables they may access.

In most cases, query the views.

## Common catalog queries

The examples use the e-commerce sample database.

The relational tables (vertex and edge tables have the class types `'VERTEX'` and `'EDGE'`, views `'VCLASS'`):

```sql
SELECT class_name FROM db_class
WHERE is_system_class = 'NO' AND class_type = 'CLASS'
ORDER BY class_name;
```

| class_name |
|---|
| countries |
| order_items |
| orders |

The columns of a table, in order:

```sql
SELECT attr_name, data_type, prec, scale, is_nullable
FROM db_attribute
WHERE class_name = 'orders'
ORDER BY def_order;
```

| attr_name | data_type | prec | scale | is_nullable |
|---|---|---|---|---|
| id | INTEGER | 10 | 0 | NO |
| customer_id | INTEGER | 10 | 0 | NO |
| shipped_date | DATE | 10 | 0 | YES |
| shipping_cost | NUMERIC | 10 | 2 | NO |
| ship_address | STRING | 128 | 0 | NO |
| order_date | DATE | 10 | 0 | NO |

The indexes of a table with their key columns:

```sql
SELECT i.index_name, k.key_attr_name, i.is_unique, i.is_primary_key, i.is_foreign_key
FROM db_index i JOIN db_index_key k ON i.class_name = k.class_name AND i.index_name = k.index_name
WHERE i.class_name = 'orders'
ORDER BY i.index_name, k.key_order;
```

| index_name | key_attr_name | is_unique | is_primary_key | is_foreign_key |
|---|---|---|---|---|
| fk_orders_customer_id | customer_id | NO | NO | YES |
| idx_orders_order_date | order_date | NO | NO | NO |
| idx_orders_shipped_date | shipped_date | NO | NO | NO |
| pk_orders_id | id | YES | YES | NO |

Other views answer other questions:

| To find | Query |
|---|---|
| Views and their queries | [db_vclass](https://www.coradb.ai/manual/sql/catalog_views.html#db_vclass) |
| Permissions on a table | [db_auth](https://www.coradb.ai/manual/sql/catalog_views.html#db_auth) |
| Partitions of a table | [db_partition](https://www.coradb.ai/manual/sql/catalog_views.html#db_partition) |
| Triggers on a table | [db_trig](https://www.coradb.ai/manual/sql/catalog_views.html#db_trig) |
| Stored functions and procedures | [db_stored_procedure](https://www.coradb.ai/manual/sql/catalog_views.html#db_stored_procedure) |
| Collations and charsets | [db_collation](https://www.coradb.ai/manual/sql/catalog_views.html#db_collation), [db_charset](https://www.coradb.ai/manual/sql/catalog_views.html#db_charset) |
| Superclasses | [db_direct_super_class](https://www.coradb.ai/manual/sql/catalog_views.html#db_direct_super_class) |

In corasql, the session commands `;schema table_name` and `;info` show the same information without writing a query, and [SHOW](https://www.coradb.ai/manual/sql/query/show.html) statements such as **SHOW COLUMNS** and **SHOW INDEX** return it as result sets.


## Catalog authorization

- The catalog classes and views are owned by **DBA**.
- Only **DBA** and members of the **DBA** group can read the catalog classes. Other users get an error such as `SELECT is not authorized on _db_class.`
- Every user can read the catalog views. A user other than **DBA** sees only the tables the user owns, tables owned by a group the user belongs to, and tables on which the user has **SELECT** permission. In the e-commerce database, where **DBA** owns all tables, the user **PUBLIC** therefore finds no user tables in `db_class`.
- Nobody, not even **DBA**, can change the catalog directly. **UPDATE**, **INSERT** and **DELETE** on a catalog class fail with an authorization error (`UPDATE is not authorized on _db_class.`), and catalog views are not updatable (`Vclass db_class is not updatable.`). The catalog changes only through DDL, user and permission statements.


## Querying the catalog

CoraDB stores the names of tables, views, columns, indexes, triggers and methods in lowercase, whatever case they were written in. Compare them with lowercase strings:

```sql
CREATE TABLE GiftCard (Code VARCHAR(16));

SELECT class_name FROM db_class WHERE class_name = 'GiftCard';   -- no rows
SELECT class_name FROM db_class WHERE class_name = 'giftcard';   -- giftcard
SELECT attr_name FROM db_attribute WHERE class_name = 'giftcard';   -- code
```

User names are stored in uppercase:

```sql
CREATE USER analyst;

SELECT name FROM db_user WHERE name = 'ANALYST';   -- ANALYST
```

With the default collation `utf8_bin`, string comparisons are case-sensitive, so `LOWER()` or `UPPER()` on the search value avoids misses when the case is not known: `WHERE class_name = LOWER('GiftCard')`.
