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.idMulti-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:
- Use consistent naming
snake_case or camelCase, pick one standard
Keep names concise and descriptive
- Group related columns
Place primary keys, constraints, and metadata together:
Table orders { id int [pk] user_id int [ref: > users.id] created_at timestamp }
- 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