DictionaryLeap

Guide

How to export your database schema for a data dictionary

A data dictionary describes columns. It does not need the rows stored in those columns. A structure-only export is enough: schema, table, column name, data type, whether the column allows null, and any primary or foreign key.

Upload that CSV, or paste a CREATE TABLE script, on the build page. Leave sample values off. DictionaryLeap does not connect to your database, and the original rows stay there.

The free preview shows the first 25 columns and the first glossary domain. The Dataset Pack is $49 for one table of up to 200 columns, with a flat glossary plus one domain of the hierarchy, and a glossary CSV and SKOS for that domain. The Database Pack is $249 for up to 50 tables and 2,000 columns, with the full glossary and taxonomy hierarchy, all parent and child checks, an Excel glossary sheet, a glossary CSV, and SKOS. Each pack is a one-time price for that upload. It is not a subscription, and nothing renews.

What the file should contain

Use these header names. Letter case does not matter. A catalog file needs table_name, column_name, and data_type (or udt_name). The other columns are optional, and they are used when they are present.

ColumnRequiredWhat it is
table_schemaNoSchema or database name. Keeps two tables with the same name apart.
table_nameYesTable or view name.
column_nameYesColumn name.
data_typeYesType name. udt_name is accepted if data_type is absent.
is_nullableNoYES or NO.
constraint_typeNoPRIMARY KEY, FOREIGN KEY, or PRIMARY KEY, FOREIGN KEY.
referenced_table_nameNoTable a foreign key points at.
referenced_column_nameNoColumn a foreign key points at.

A column that is both a primary key and a foreign key should say PRIMARY KEY, FOREIGN KEY. The upload records the primary key and still keeps the referenced table and column. Empty key fields are fine. A CREATE TABLE script is the other accepted input. The upload reads columns and keys written inside CREATE TABLE. It does not read a later ALTER TABLE statement.

This file describes the schema. It is not the dictionary. A blank data dictionary template is the sheet to fill when you will write definitions by hand. Uploading this export drafts that dictionary instead. The data dictionary generator guide explains the preview and the paid packs. Choosing between a spreadsheet and a generated draft is covered in the Excel or Google Sheets comparison.

How to do it

  1. Run the export. Run the catalog query for your database, or export CREATE TABLE statements.
  2. Save the file. Save the query result as a CSV with the header row, or copy the CREATE TABLE script into a .sql file.
  3. Upload it. Open the build page and upload the file. Leave sample values off. DictionaryLeap does not connect to the database.
  4. Read the preview. The free preview shows the first 25 columns and the first glossary domain.

Catalog queries

PostgreSQL and MySQL were run on local servers, not a production database. SQL Server and Snowflake were checked against vendor documentation and were not run on a live server. Add a filter on the schema column if you want one schema instead of every object the login can see. The Snowflake data dictionary and PostgreSQL data dictionary guides are the platform pages, including column comments. The BigQuery data dictionary and SQL Server data dictionary guides export names, types, and the description already stored on each column. The MySQL data dictionary guide adds the column comment to the MySQL catalog query, and it covers mysqldump --no-data.

PostgreSQL

This query was run on a local PostgreSQL 16.15 server against a small schema (tables, a view, primary keys, a composite primary key, foreign keys, and a column that was both). It was not run on a production database. The result CSV was accepted by the DictionaryLeap upload parser.

The views return objects the current role can access. Key rows need ownership of the table, or a privilege other than SELECT. On that local server, a role with only SELECT still returned the columns and left the key fields empty. Add AND c.table_schema = 'public' (use your schema name) if you do not want every schema.

data_type is the SQL type name, such as integer or character varying. Length and precision are not in that column.

PostgreSQL data dictionary is the guide for this platform. It includes the column comment in the CSV.

CSV query

SELECT
  c.table_schema,
  c.table_name,
  c.column_name,
  c.data_type,
  c.is_nullable,
  CASE
    WHEN pk.column_name IS NOT NULL AND fk.column_name IS NOT NULL THEN 'PRIMARY KEY, FOREIGN KEY'
    WHEN pk.column_name IS NOT NULL THEN 'PRIMARY KEY'
    WHEN fk.column_name IS NOT NULL THEN 'FOREIGN KEY'
    ELSE NULL
  END AS constraint_type,
  fk.referenced_table_name,
  fk.referenced_column_name
FROM information_schema.columns AS c
LEFT JOIN (
  SELECT DISTINCT
    kcu.table_schema,
    kcu.table_name,
    kcu.column_name
  FROM information_schema.table_constraints AS tc
  JOIN information_schema.key_column_usage AS kcu
    ON kcu.constraint_catalog = tc.constraint_catalog
   AND kcu.constraint_schema = tc.constraint_schema
   AND kcu.constraint_name = tc.constraint_name
  WHERE tc.constraint_type = 'PRIMARY KEY'
) AS pk
  ON pk.table_schema = c.table_schema
 AND pk.table_name = c.table_name
 AND pk.column_name = c.column_name
LEFT JOIN (
  SELECT DISTINCT ON (kcu.table_schema, kcu.table_name, kcu.column_name)
    kcu.table_schema,
    kcu.table_name,
    kcu.column_name,
    ref.table_name AS referenced_table_name,
    ref.column_name AS referenced_column_name
  FROM information_schema.table_constraints AS tc
  JOIN information_schema.key_column_usage AS kcu
    ON kcu.constraint_catalog = tc.constraint_catalog
   AND kcu.constraint_schema = tc.constraint_schema
   AND kcu.constraint_name = tc.constraint_name
  JOIN information_schema.referential_constraints AS rc
    ON rc.constraint_catalog = tc.constraint_catalog
   AND rc.constraint_schema = tc.constraint_schema
   AND rc.constraint_name = tc.constraint_name
  LEFT JOIN information_schema.key_column_usage AS ref
    ON ref.constraint_catalog = rc.unique_constraint_catalog
   AND ref.constraint_schema = rc.unique_constraint_schema
   AND ref.constraint_name = rc.unique_constraint_name
   AND ref.ordinal_position = kcu.position_in_unique_constraint
  WHERE tc.constraint_type = 'FOREIGN KEY'
  ORDER BY kcu.table_schema, kcu.table_name, kcu.column_name, kcu.constraint_name
) AS fk
  ON fk.table_schema = c.table_schema
 AND fk.table_name = c.table_name
 AND fk.column_name = c.column_name
WHERE c.table_schema NOT IN ('pg_catalog', 'information_schema')
ORDER BY c.table_schema, c.table_name, c.ordinal_position;

Save the result as a CSV with the header row. If a column has more than one foreign key, the query keeps one referenced pair, chosen by constraint name.

CREATE TABLE with pg_dump

pg_dump --schema-only --no-owner --no-privileges --dbname=DBNAME

These flags were run locally. --schema-only writes definitions and no row data. --no-owner and --no-privileges leave out ownership and grants. On that dump, primary and foreign keys were ALTER TABLE statements after CREATE TABLE. The upload does not read ALTER TABLE, so those keys were missing. Use the CSV query when you want keys. The CREATE TABLE statements still carry names, types, and NOT NULL.

MySQL

This query was run on a local MySQL 8.0.46 server against the same kind of schema. It was not run on a production database. The result used the column names the upload accepts, including varchar(255) from COLUMN_TYPE. ROW_NUMBER() needs MySQL 8.0 or later.

System schemas mysql, information_schema, performance_schema, and sys are left out. Add AND c.TABLE_SCHEMA = 'your_database' to keep a single database. The account must be allowed to see the tables.

MySQL data dictionary is the guide for this platform. It adds the column comment. This query does not. It also covers mysqldump --no-data.

CSV query

SELECT
  c.TABLE_SCHEMA AS table_schema,
  c.TABLE_NAME AS table_name,
  c.COLUMN_NAME AS column_name,
  c.COLUMN_TYPE AS data_type,
  c.IS_NULLABLE AS is_nullable,
  CASE
    WHEN pk.COLUMN_NAME IS NOT NULL AND fk.COLUMN_NAME IS NOT NULL THEN 'PRIMARY KEY, FOREIGN KEY'
    WHEN pk.COLUMN_NAME IS NOT NULL THEN 'PRIMARY KEY'
    WHEN fk.COLUMN_NAME IS NOT NULL THEN 'FOREIGN KEY'
    ELSE NULL
  END AS constraint_type,
  fk.referenced_table_name,
  fk.referenced_column_name
FROM information_schema.COLUMNS AS c
LEFT JOIN (
  SELECT DISTINCT
    kcu.TABLE_SCHEMA,
    kcu.TABLE_NAME,
    kcu.COLUMN_NAME
  FROM information_schema.TABLE_CONSTRAINTS AS tc
  JOIN information_schema.KEY_COLUMN_USAGE AS kcu
    ON kcu.CONSTRAINT_SCHEMA = tc.CONSTRAINT_SCHEMA
   AND kcu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME
   AND kcu.TABLE_SCHEMA = tc.TABLE_SCHEMA
   AND kcu.TABLE_NAME = tc.TABLE_NAME
  WHERE tc.CONSTRAINT_TYPE = 'PRIMARY KEY'
) AS pk
  ON pk.TABLE_SCHEMA = c.TABLE_SCHEMA
 AND pk.TABLE_NAME = c.TABLE_NAME
 AND pk.COLUMN_NAME = c.COLUMN_NAME
LEFT JOIN (
  SELECT
    ranked.TABLE_SCHEMA,
    ranked.TABLE_NAME,
    ranked.COLUMN_NAME,
    ranked.REFERENCED_TABLE_NAME AS referenced_table_name,
    ranked.REFERENCED_COLUMN_NAME AS referenced_column_name
  FROM (
    SELECT
      kcu.TABLE_SCHEMA,
      kcu.TABLE_NAME,
      kcu.COLUMN_NAME,
      kcu.REFERENCED_TABLE_NAME,
      kcu.REFERENCED_COLUMN_NAME,
      ROW_NUMBER() OVER (
        PARTITION BY kcu.TABLE_SCHEMA, kcu.TABLE_NAME, kcu.COLUMN_NAME
        ORDER BY kcu.CONSTRAINT_NAME
      ) AS rn
    FROM information_schema.KEY_COLUMN_USAGE AS kcu
    WHERE kcu.REFERENCED_TABLE_NAME IS NOT NULL
  ) AS ranked
  WHERE ranked.rn = 1
) AS fk
  ON fk.TABLE_SCHEMA = c.TABLE_SCHEMA
 AND fk.TABLE_NAME = c.TABLE_NAME
 AND fk.COLUMN_NAME = c.COLUMN_NAME
WHERE c.TABLE_SCHEMA NOT IN ('mysql', 'information_schema', 'performance_schema', 'sys')
ORDER BY c.TABLE_SCHEMA, c.TABLE_NAME, c.ORDINAL_POSITION;

Save the result as a CSV with the header row. data_type is the full COLUMN_TYPE, so length and precision are included. If a column has more than one foreign key, one referenced pair is kept.

CREATE TABLE

mysqldump --no-data --user=USER --host=HOST DBNAME

SHOW CREATE TABLE database_name.table_name;

mysqldump --no-data and SHOW CREATE TABLE were run on the local MySQL 8.0.46 server. Both put PRIMARY KEY and FOREIGN KEY inside CREATE TABLE, and the upload recorded those keys. The dump also contains DROP statements and session settings. The upload reads the CREATE TABLE statements and ignores the rest. --user and --host are the documented connection options. They were not needed for the local socket used here.

SQL Server

This query was checked against the current Microsoft pages for INFORMATION_SCHEMA.COLUMNS, TABLE_CONSTRAINTS, KEY_COLUMN_USAGE, and REFERENTIAL_CONSTRAINTS. It was not run on a SQL Server instance. Those pages apply to SQL Server, Azure SQL Database, Azure SQL Managed Instance, and SQL database in Microsoft Fabric. The views return objects the current login can see, and Microsoft describes them as a subset of the catalog.

data_type is the system type name, without length. For a composite foreign key, the referenced column is the one with the same ORDINAL_POSITION. Microsoft's current page calls that value the column ordinal position. An older Microsoft article on foreign-key metadata describes it as the column order inside the constraint, which is how the two sides are matched here. Spot-check one composite key before you upload a large schema.

There is no information_schema query on those pages that returns a full CREATE TABLE statement. Paste a CREATE TABLE script if you already have one with the keys inside the parentheses. Keys written later as ALTER TABLE are not read.

SQL Server data dictionary is the guide for this platform. It adds the MS_Description extended property. This query does not.

CSV query

SELECT
  c.TABLE_SCHEMA AS table_schema,
  c.TABLE_NAME AS table_name,
  c.COLUMN_NAME AS column_name,
  c.DATA_TYPE AS data_type,
  c.IS_NULLABLE AS is_nullable,
  CASE
    WHEN pk.COLUMN_NAME IS NOT NULL AND fk.key_column IS NOT NULL THEN 'PRIMARY KEY, FOREIGN KEY'
    WHEN pk.COLUMN_NAME IS NOT NULL THEN 'PRIMARY KEY'
    WHEN fk.key_column IS NOT NULL THEN 'FOREIGN KEY'
    ELSE NULL
  END AS constraint_type,
  fk.referenced_table_name,
  fk.referenced_column_name
FROM INFORMATION_SCHEMA.COLUMNS AS c
LEFT JOIN (
  SELECT DISTINCT
    kcu.TABLE_SCHEMA,
    kcu.TABLE_NAME,
    kcu.COLUMN_NAME
  FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc
  INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS kcu
    ON kcu.CONSTRAINT_CATALOG = tc.CONSTRAINT_CATALOG
   AND kcu.CONSTRAINT_SCHEMA = tc.CONSTRAINT_SCHEMA
   AND kcu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME
   AND kcu.TABLE_SCHEMA = tc.TABLE_SCHEMA
   AND kcu.TABLE_NAME = tc.TABLE_NAME
  WHERE tc.CONSTRAINT_TYPE = 'PRIMARY KEY'
) AS pk
  ON pk.TABLE_SCHEMA = c.TABLE_SCHEMA
 AND pk.TABLE_NAME = c.TABLE_NAME
 AND pk.COLUMN_NAME = c.COLUMN_NAME
OUTER APPLY (
  SELECT TOP (1)
    fkcu.COLUMN_NAME AS key_column,
    referenced.TABLE_NAME AS referenced_table_name,
    referenced.COLUMN_NAME AS referenced_column_name
  FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS rc
  INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS fkcu
    ON fkcu.CONSTRAINT_CATALOG = rc.CONSTRAINT_CATALOG
   AND fkcu.CONSTRAINT_SCHEMA = rc.CONSTRAINT_SCHEMA
   AND fkcu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME
  INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS referenced
    ON referenced.CONSTRAINT_CATALOG = rc.UNIQUE_CONSTRAINT_CATALOG
   AND referenced.CONSTRAINT_SCHEMA = rc.UNIQUE_CONSTRAINT_SCHEMA
   AND referenced.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME
   AND referenced.ORDINAL_POSITION = fkcu.ORDINAL_POSITION
  WHERE fkcu.TABLE_SCHEMA = c.TABLE_SCHEMA
    AND fkcu.TABLE_NAME = c.TABLE_NAME
    AND fkcu.COLUMN_NAME = c.COLUMN_NAME
  ORDER BY fkcu.CONSTRAINT_NAME, referenced.TABLE_NAME, referenced.COLUMN_NAME
) AS fk
WHERE c.TABLE_SCHEMA NOT IN (N'sys', N'INFORMATION_SCHEMA')
ORDER BY c.TABLE_SCHEMA, c.TABLE_NAME, c.ORDINAL_POSITION;

Save the result as a CSV with the header row. Add AND c.TABLE_SCHEMA = N'dbo' if you only want that schema. If a column has more than one foreign key, one referenced pair is kept.

Snowflake

Select the database in the worksheet first. Each database has its own INFORMATION_SCHEMA, and the views return objects the current role can access. These queries were checked against the current Snowflake pages for COLUMNS, TABLES, GET_DDL, and REGEXP_REPLACE. They were not run on a Snowflake account.

Snowflake's information schema does not list which column belongs to a primary or foreign key. The CSV below is names, data types, and nullability only. SHOW PRIMARY KEYS lists primary-key columns, but that result is not the CSV shape the upload reads. Use the CREATE TABLE query when you need keys in the file.

Snowflake data dictionary is the guide for this platform. It includes the column comment in the CSV.

CSV query

SELECT
  table_schema,
  table_name,
  column_name,
  data_type,
  is_nullable
FROM information_schema.columns
WHERE table_schema <> 'INFORMATION_SCHEMA'
ORDER BY table_schema, table_name, ordinal_position;

Save the result as a CSV with the header row. Unquoted names come back in uppercase. The upload accepts that. The file includes tables and views. Key columns are empty, so any join guessed from a column name is marked inferred.

CREATE TABLE with GET_DDL

SELECT
  table_schema,
  table_name,
  REGEXP_REPLACE(
    REGEXP_REPLACE(
      GET_DDL('TABLE', table_schema || '.' || table_name),
      'or replace ',
      '',
      1,
      1,
      'i'
    ),
    'hybrid table',
    'TABLE',
    1,
    1,
    'i'
  ) AS create_table_sql
FROM information_schema.tables
WHERE table_type = 'BASE TABLE'
  AND table_schema <> 'INFORMATION_SCHEMA'
ORDER BY table_schema, table_name;

GET_DDL returns the statement that recreates the table. The documented hybrid-table example starts with create or replace HYBRID TABLE and includes primary key (...) inside the statement. This query removes the first or replace and rewrites the first hybrid table to TABLE, because the upload looks for CREATE TABLE. Copy the create_table_sql values into one script. If a statement still says OR REPLACE, delete those two words before you paste it. Do not run the edited script in Snowflake as a substitute for the original table. A foreign key is included only when Snowflake's DDL includes it. Quoted mixed-case names may need extra double quotes around the GET_DDL name.

dbt

DictionaryLeap does not connect to dbt Cloud, dbt Core, or the warehouse. Do not upload a schema.yml. Export the columns from the schema dbt builds, using the warehouse query on this page, or paste the CREATE TABLE statements for those models.

The dbt schema.yml in a pack is an output you can edit and commit. It is not an input. The file is version 2, with one model per table and a description on each column. The dbt schema.yml generator guide covers drafting that file from this export.

FAQ

Draft the dictionary

The free preview shows the first 25 columns and the first glossary domain. The Dataset Pack is $49 for one table of up to 200 columns, with a flat glossary plus one domain of the hierarchy, and a glossary CSV and SKOS for that domain. The Database Pack is $249 for up to 50 tables and 2,000 columns, with the full glossary and taxonomy hierarchy, all parent and child checks, an Excel glossary sheet, a glossary CSV, and SKOS. Each pack is a one-time price for that upload. It is not a subscription, and nothing renews.

Prefer to write the dictionary yourself? Download the blank data dictionary template.

Build my dictionary