DBML Editor & Syntax | ERD Generator Docs

DBML (Database Markup Language) is a clean, human-readable language for defining database schemas across platforms. It’s designed to be simple, database-agnostic, and easy to edit β€” making it ideal for your ERD Generator’s schema editor.

In this page you’ll learn:

  • What DBML is
  • Core syntax and examples
  • How to use the in-app editor
  • Tips for readable, maintainable schema files

πŸ“Œ What is DBML?

DBML is a declarative language to describe tables, fields, relationships, enums, and notes in your database schema. It is both compact and expressive, making schemas easier to write and maintain.

Unlike SQL DDL, which is database-specific, DBML stays consistent across engines and feeds directly into diagram generators like ERD Generator.


🧱 Core DBML Concepts

Table Definitions

Every table starts with the Table keyword followed by a name and curly braces:

'''dbml Table users { id int [pk, increment] email varchar(255) [unique, not null] created_at timestamp } '''

  • 'pk': Primary key
  • 'increment': Auto-increment column
  • Square brackets [] denote column settings like constraints and metadata.

Column Settings

Column settings go inside '[]':

Setting Meaning
'pk' Primary key
'unique' Enforces uniqueness
'not null' Disallows null values
'default: value' Default expression/value
'note: 'text'' Adds an informational note visible in the editor

Example with multiple settings:

'''dbml Table products { id int [pk] sku varchar [unique, not null] price decimal [default: 0] note: 'Product catalog' } '''


πŸ”— Defining Relationships

Relationships describe how tables relate to one another.

Long form:

'''dbml Ref: users.id < orders.user_id '''

Inline form (within a table):

'''dbml Table orders { user_id int [ref: > users.id] } '''

Both forms define a foreign key constraint that expresses one-to-many relations between tables.


πŸ“š Enum Definitions

Enums let you constrain a column to predefined values:

'''dbml Enum status { active inactive pending } '''

Using enums increases schema clarity and helps convey intent in diagrams.


πŸ“ Notes and Comments

You can attach documentation directly to DBML elements using notes:

Table users {
  id int
  name varchar
  Note: 'Stores core user account details'
}

And add inline or block comments:

// This is a one-to-many relationship
Ref: posts.user_id > users.id

Multi-line notes:

 
Note user_notes {
  '''
  This schema is designed for analytics.
  It may grow over time.
  '''
}

DBML supports both single-line and multi-line strings for expressive notes. See the editor's inline help for syntax reference.

πŸ› οΈ Editing DBML In-App

In ERD Generator, the DBML editor typically uses a code editor (like Monaco) that supports:

Syntax highlighting

Real-time preview

Auto-completion (in some cases)

Inline error detection

Start typing your schema on the left, and watch the diagram update in real time on the right. This tight feedback loop improves productivity and reduces errors.

Tips for Smooth Editing

Use Ctrl / Cmd + / to toggle line comments

Run Ctrl / Cmd + Q to open the command palette

Review errors as you type β€” the editor will catch syntax mismatches early

Keep schemas DRY by reusing patterns where possible

πŸ‘ Best Practices for Readability

Readable DBML is easier to maintain and share:

  1. Use consistent naming

snake_case or camelCase, pick one standard

Keep names concise and descriptive

  1. Group related columns

Place primary keys, constraints, and metadata together:

Table orders { id int [pk] user_id int [ref: > users.id] created_at timestamp }

  1. Add clear notes

Use notes to explain intent, especially for unusual keys or constraints.

πŸš€ Example Complete Schema Table users { id int [pk, increment] email varchar(255) [unique, not null, note: 'Login email'] created_at timestamp [default: now()] }

Table posts { id int [pk, increment] title varchar content text user_id int [ref: > users.id] created_at timestamp }

Ref: posts.user_id > users.id

This simple example defines two tables and a one-to-many relationship.

πŸ“¦ Summary

DBML provides a simple, powerful way to define database schemas in a readable, agnostic format that feeds into visual diagram tools like ERD Generator. It strikes a balance between readability and expressiveness, making it ideal for documentation, collaboration, and rapid iteration.

πŸ‘‰ Next Steps

Explore SQL β†’ DBML Converter to import existing schemas

Try creating enums, notes, and table groups

Use the keyboard shortcuts to speed up editing