Enrichment & Visualization
This part covers features specific to diagram & wiki tools like dbdiagram.io & dbdocs.io. These constructs have no SQL equivalent and are used solely to annotate and support the visualization.
Note Definition
Note allows users to give description for a particular DBML element. Two syntax forms are supported:
Table users {
id int [pk]
name varchar
Note: 'This is a note of this table'
// or
Note {
'This is a note of this table'
}
}
Note's value is a string. If your note spans over multiple lines, you can use multi-line string to define your note.
Project Notes
Project DBML {
Note: '''
# DBML - Database Markup Language
DBML (database markup language) is a simple, readable DSL designed to define database structures.
## Benefits
* It is simple, flexible and highly human-readable
* It is database agnostic, focusing on the essential database structure definition without worrying about the detailed syntaxes of each database
* Comes with a free, simple database visualiser at [dbdiagram.io](http://dbdiagram.io)
'''
}
Table Notes
Table users {
id int [pk]
name varchar
Note: 'Stores user data'
}
Column Notes
You can add notes to your columns, so you can easily refer to it when hovering over the column in the diagram canvas.
column_name column_type [note: 'replace text here']
Example,
Table orders {
status varchar [
note: '''
💸 1 = processing,
✔️ 2 = shipped,
❌ 3 = cancelled,
😔 4 = refunded
''']
}
Index Notes
indexes {
created_at [name: 'created_at_index', note: 'Date']
}
TableGroup Notes
TableGroup e_commerce [note: 'Contains tables that are related to e-commerce system'] {
merchants
countries
// or
Note: 'Contains tables that are related to e-commerce system'
}
Sticky Notes
You can add sticky notes to the diagram canvas to serve as a quick reminder or to elaborate on a complex idea.
Example,
Table jobs {
...
}
Note single_line_note {
'This is a single line note'
}
Note multiple_lines_note {
'''
This is a multiple lines note
This string can spans over multiple lines.
'''
}
TableGroup
TableGroup allows users to group the related or associated tables together.
TableGroup tablegroup_name { // tablegroup is case-insensitive.
table1
table2
table3
}
// example
TableGroup e_commerce1 {
merchants
countries
}
TableGroup Notes
Table groupings can be annotated with notes that describe their meaning and purpose.
TableGroup e_commerce [note: 'Contains tables that are related to e-commerce system'] {
merchants
countries
// or
Note: 'Contains tables that are related to e-commerce system'
}
TableGroup Settings
Each table group can take optional settings, defined within square brackets: [setting1: value1, setting2: value2, setting3, setting4]
The list of table group settings you can use:
note: 'string to add notes': add a note to this table group.color: <color_code>: change the table group color. See Colors for accepted color formats.
Colors
Color values are specified as hex codes in shorthand or full form: #rgb or #rrggbb.
Table header color
Use headercolor on a table to change its header color:
Table users [headercolor: #3498DB] {
id integer [primary key]
username varchar(255) [not null, unique]
}
Relationship line color
Use color on a relationship to change the color of the relationship line:
// short form
Ref: products.merchant_id > merchants.id [color: #79AD51]
// long form
Ref {
products.merchant_id > merchants.id [color: #79AD51]
}
TableGroup color
Use color on a table group to change its background color:
TableGroup e_commerce [color: #3498DB] {
merchants
countries
}