What is DBML? The Database Markup Language explained

DBML, short for Database Markup Language, is a small domain-specific language for describing database schemas. Instead of drawing boxes by hand or reverse engineering a diagram from DDL, you write tables, columns, and relationships as plain text, and tooling turns that text into an entity relationship diagram.

What DBML looks like

A schema is a set of Table blocks, with relationships declared inline:

Table users {
  id uuid [pk]
  email varchar [not null, unique]
  created_at timestamp
}

Table posts {
  id uuid [pk]
  author_id uuid [ref: > users.id]
  title varchar
  status post_status
}

Enum post_status {
  draft
  published
  archived
}

That is the entire language in miniature: [pk] marks a primary key, [ref: > users.id] declares a many-to-one foreign key, and Enum blocks define reusable value sets that columns can use as types.

Why teams use DBML instead of drawing diagrams

  • It lives in version control. Schema changes show up as readable diffs in pull requests, not as screenshots of a drawing tool.
  • It is the single source of truth. The diagram is generated from the text, so the picture can never drift out of date.
  • It is fast to write. A table takes seconds to declare, and relationships are one attribute, not a drag-and-drop gesture.
  • It converts both ways. Tools can generate DBML from SQL dumps and export SQL from DBML, so it fits into existing databases rather than replacing them.

DBML and large schemas

Standard DBML describes one file at a time, which gets unwieldy past a few dozen tables. Some tools extend the language with module imports. DB Planner supports the use * from './file' syntax, which resolves references across every file in a project, so a large schema can be organized by domain, one file per area, while still rendering as one connected diagram. See the features overview for how that works on the board.

Getting started with DBML

The quickest start is not writing DBML at all: import an existing SQL schema and let the tool generate the DBML for you. DB Planner converts DDL from Postgres, MySQL, MSSQL, and Snowflake, then lets you refine the result in a built-in editor with syntax highlighting while the diagram updates live.