A data dictionary is a document that describes the data in a dataset or database: every table and field, its name, meaning, data type and allowed values. USGS puts it as a way to "catalog and communicate the structure and content of data", so that anyone using the data reads each field the same way.
The sections below cover what goes in one, a worked example, how to produce the technical half from a live database with SQL, and how to keep it in a machine-readable file.
What a data dictionary contains
USGS says the contents of a dictionary can vary, and lists the elements that typically appear:
- A list of data objects (tables, fields) with names and definitions.
- Properties of each data element: type, size, whether it can be null, whether it is optional, and which indexes exist.
- Entity-relationship diagrams and other system-level diagrams.
- Reference data, such as classification codes and descriptive domains.
- Codes for missing data and quality indicators.
- Business rules for validating the schema or the data quality.
In practice the core is a table with one row per field. A dictionary for a small orders table might look like this:
| Field | Type | Nullable | Definition | Allowed values |
|---|---|---|---|---|
order_id | integer | No | Unique identifier of the order. Primary key. | Positive integers |
customer_id | integer | No | Identifier of the customer who placed the order. | Must exist in customers |
status | text | No | Where the order is in fulfilment. | pending, shipped, cancelled |
total_cents | integer | No | Order total in cents, including tax, in the order's currency. | 0 or greater |
shipped_at | timestamp (UTC) | Yes | When the order left the warehouse. Null until it ships. | Any time after order creation |
The two columns people most often skip are the ones that matter most: the definition and the allowed values. A column named total tells you nothing about whether it holds dollars or cents, or whether tax is included. The dictionary is where that gets written down once.
Why teams keep one
USGS names several uses. The main one is shared understanding: "Shared dictionaries ensure that the meaning, relevance, and quality of data elements are the same for all users." Beyond that it lists:
- Documentation. New developers and analysts get the structure without reverse-engineering it from code.
- Application design. Developers building forms and reports can pick the correct data types and limits.
- Systems analysis and integration. Analysts mapping data flows can see how to merge or transform datasets.
- Decision making. It supports planning for further data collection and project work.
USGS also makes a less obvious point: writing a dictionary exposes problems. Weak table design, incomplete definitions and outdated documentation become visible once you try to describe each field. That is a benefit, because you find the problem before a consumer of the data does.
Data dictionary vs. schema, glossary and catalog
The terms overlap, so here is how they usually differ:
| Artifact | Answers | Scope |
|---|---|---|
| Schema (DDL) | What tables and columns exist, and with what types? | One database. Machine-enforced. |
| Data dictionary | What does each field mean, and what values are valid? | One dataset or database. Written for humans, sometimes also machines. |
| Business glossary | What does a business term such as "active customer" mean? | The whole organization. Not tied to a column. |
| Data catalog | Which datasets exist, who owns them, where are they? | Many datasets. Often searchable. |
The schema is the part the database enforces. The dictionary adds the meaning that the schema cannot express. If you are also deciding where this data should live for reporting, see what a data warehouse is, where a dictionary is especially useful because data arrives from several source systems with different conventions.
How to generate the technical part from PostgreSQL
Much of the structural half can be read from the database instead of typed by hand. PostgreSQL exposes it in information_schema.columns, which has columns such as table_name, column_name, data_type, is_nullable, column_default and character_maximum_length. This query lists them for the public schema:
SELECT table_name, column_name, data_type, is_nullable,
column_default, character_maximum_length
FROM information_schema.columns
WHERE table_schema = 'public'
ORDER BY table_name, ordinal_position;
Filter on table_schema, because the same table name can exist in more than one schema. In the PostgreSQL documentation, is_nullable is YES if the column is possibly nullable and NO if it is known not to be. character_maximum_length is null for anything that is not a character or bit string type, or when no maximum was declared. Other databases have their own system views, so check your vendor's documentation for the equivalent.
That query gives you names, types and nullability. It cannot give you definitions, units or business rules. Those have to be written by someone who knows the data.
Store definitions in the database with COMMENT
PostgreSQL lets you attach the written definition to the object itself with COMMENT ON:
COMMENT ON TABLE orders IS 'One row per customer order.';
COMMENT ON COLUMN orders.total_cents IS 'Order total in cents, including tax.';
Per the documentation, a new COMMENT replaces the old one, setting it to NULL or an empty string removes it, and comments are dropped automatically when the object is dropped. You can see them in psql with the \d family of commands, and other tools can read them with the obj_description and col_description functions.
The advantage is that the definition travels with the schema, so a migration that changes a column is a natural place to update its comment. One warning from the same page: any user connected to the database can see its comments, so do not put sensitive information in them.
Keep it machine-readable with a Table Schema
For data that lives in files such as CSV rather than a database, the Frictionless Table Schema specification defines a JSON descriptor that works as a dictionary a program can check data against. The descriptor must contain fields, an ordered array with one entry per column. Each field needs a name. It can also have a type (assumed to be string if omitted), a human-readable description, and constraints. The spec's required constraint defaults to false, unique requires every value to differ, and enum requires a value to match one entry of a list exactly. A top-level primaryKey names the field or fields that identify each row. Example:
{
"fields": [
{
"name": "order_id",
"type": "integer",
"description": "Unique identifier of the order",
"constraints": { "required": true, "unique": true }
},
{
"name": "status",
"type": "string",
"description": "Fulfilment state of the order",
"constraints": { "enum": ["pending", "shipped", "cancelled"] }
}
],
"primaryKey": "order_id"
}
The same file is documentation for a person and a validation rule set for a tool. If your data starts life as a spreadsheet export, it helps to check it against a descriptor like this before it goes anywhere else.
How to write one that stays useful
- Define every field in a sentence a newcomer can act on. Include units ("cents", "kilograms", "UTC") and say what null means.
- List allowed values explicitly. For coded fields, spell out each code. For missing data, record the code used, as USGS suggests.
- Record the rules. Foreign key relationships, valid ranges and cross-field rules belong here, even if some are also enforced in the database.
- Update it in the same change as the schema. If the dictionary lives in a different tool from the code, it will fall behind. Comments in migrations or a descriptor file in the same repository avoid that.
- Name an owner. A dictionary nobody owns is the outdated documentation USGS warns about.
If you are still learning how tables, columns and types fit together, SQL for beginners covers the vocabulary a dictionary assumes.
If your dictionary is already out of date
Start by generating the structural half again from the live database, using the information_schema query above, and diff it against the document. Every field that appears in one and not the other is a gap to resolve. Then fix the definitions for the columns people ask about most, rather than trying to document everything at once. A short, accurate dictionary is more useful than a complete one nobody trusts.
Frequently asked questions
- What is the difference between a data dictionary and a data catalog?
- A data dictionary describes the structure and meaning of the fields inside one dataset or database: names, types, allowed values and definitions. A data catalog is an inventory of many datasets across an organization, usually with owners and search. A catalog entry often links to a dictionary for the dataset it lists.
- Does a database already have a data dictionary?
- Partly. Relational databases keep system metadata about tables, columns and types, and PostgreSQL exposes it through information_schema.columns. That metadata records structure but not meaning. Definitions, units, business rules and reference values still have to be written by people.
- Who should maintain a data dictionary?
- The people who own the data should maintain it, and changes to the schema should update it in the same change. A dictionary that is edited separately from the schema drifts out of date. USGS notes that outdated documentation reflects poorly on data stewardship.
- What format should a data dictionary use?
- Use whatever your team will actually keep current. A spreadsheet works for small datasets. Database comments keep definitions next to the schema. A machine-readable file such as a Frictionless Table Schema JSON descriptor lets tools validate data against the dictionary.