Appearance
Tables & Columns
Tables are the fundamental building blocks of your database diagram. Each table contains columns with types, constraints, and optional settings.
Defining a Table
Table table_name {
column_name column_type [settings]
}A table definition starts with the Table keyword, followed by the table name and a block enclosed in curly braces. Each line inside the block defines a column with its name, type, and optional settings.
Table users {
id int [pk, increment]
username varchar(50) [not null, unique]
email varchar(255) [not null, unique]
bio text
created_at timestamp [default: `now()`]
}Comments
Use // to add single-line comments anywhere in your DSL code:
// This table stores registered user accounts
Table users {
id int [pk, increment]
username varchar(50) [not null] // must be unique across the system
email varchar(255) [not null]
}Comments are ignored by the parser and do not appear in generated SQL output. They are useful for leaving notes for yourself or collaborators within the DSL editor.
Table Aliases
Give a table a short alias with the as keyword. This is useful for long table names — you can then reference the alias in relationships:
Table very_long_table_name as VL {
id int [pk]
name varchar(100)
}
Table other_table {
id int [pk]
fk int [ref: > VL.id]
}The alias VL can be used anywhere the full table name would appear in Ref definitions.
Schema Prefix
To place a table inside a specific database schema, use dot notation:
Table myschema.users {
id int [pk, increment]
email varchar(255) [not null]
}
Table billing.invoices {
id int [pk, increment]
user_id int [not null]
}The schema prefix is carried through to the generated SQL output. For example, PostgreSQL output will produce CREATE TABLE "myschema"."users" (...).
TIP
If you omit the schema prefix, tables are created in the database's default schema (typically public in PostgreSQL or dbo in SQL Server).
Table Colors
Customize how a table appears on the ERD canvas by assigning it a color:
Table users [color: #3498db] {
id int [pk, increment]
email varchar(255) [not null]
}
Table orders [color: #e74c3c] {
id int [pk, increment]
total decimal(10,2)
}Colors are specified as hex values and affect the table header on the canvas. This is purely visual — colors do not appear in the generated SQL.
TIP
Use colors to visually distinguish different domains in your schema. For example, blue for auth tables, red for billing, green for content.
Column Types
DBSketch accepts any SQL type string as a column type. The DSL is dialect-aware — the same type name generates appropriate SQL for each target dialect (PostgreSQL, MySQL, SQL Server, SQLite).
Below is a comprehensive reference of supported types organized by category.
Integer Types
| Type | Description |
|---|---|
int / integer | Standard 4-byte integer |
bigint | 8-byte large integer |
smallint | 2-byte small integer |
tinyint | 1-byte integer (MySQL, SQL Server) |
mediumint | 3-byte integer (MySQL) |
serial | Auto-incrementing 4-byte integer (PostgreSQL) |
bigserial | Auto-incrementing 8-byte integer (PostgreSQL) |
smallserial | Auto-incrementing 2-byte integer (PostgreSQL) |
Numeric / Decimal Types
| Type | Description |
|---|---|
float | Single-precision floating-point |
real | Single-precision floating-point (alias) |
double | Double-precision floating-point |
decimal(p,s) | Fixed-point number with precision and scale |
numeric(p,s) | Alias for decimal |
money | Currency type (PostgreSQL) |
Boolean
| Type | Description |
|---|---|
boolean / bool | True/false value |
String Types
| Type | Description |
|---|---|
varchar(n) | Variable-length string up to n characters |
char(n) | Fixed-length string of exactly n characters |
text | Unlimited-length text |
tinytext | Up to 255 bytes (MySQL) |
mediumtext | Up to 16 MB (MySQL) |
longtext | Up to 4 GB (MySQL) |
UUID
| Type | Description |
|---|---|
uuid | Universally unique identifier |
JSON Types
| Type | Description |
|---|---|
json | JSON data stored as text |
jsonb | Binary JSON with indexing support (PostgreSQL) |
Date & Time Types
| Type | Description |
|---|---|
date | Date only (no time) |
time | Time only (no date) |
timestamp | Date and time without timezone |
timestamptz | Date and time with timezone (PostgreSQL) |
timetz | Time with timezone (PostgreSQL) |
interval | Time span / duration (PostgreSQL) |
datetime | Date and time (MySQL, SQL Server) |
year | Year value (MySQL) |
Binary Types
| Type | Description |
|---|---|
bytea | Binary data (PostgreSQL) |
blob | Binary large object (MySQL) |
binary(n) | Fixed-length binary data |
varbinary(n) | Variable-length binary data |
Network Types (PostgreSQL)
| Type | Description |
|---|---|
inet | IPv4 or IPv6 host address |
cidr | IPv4 or IPv6 network address |
macaddr | MAC address |
Geometric Types (PostgreSQL)
| Type | Description |
|---|---|
point | 2D point |
line | Infinite line |
lseg | Line segment |
box | Rectangular box |
circle | Circle |
polygon | Closed polygon |
path | Open or closed geometric path |
Full-Text Search Types (PostgreSQL)
| Type | Description |
|---|---|
tsvector | Text search document |
tsquery | Text search query |
Other Types
| Type | Description |
|---|---|
xml | XML data |
bit | Fixed-length bit string |
varbit | Variable-length bit string |
hstore | Key-value pairs (PostgreSQL) |
citext | Case-insensitive text (PostgreSQL) |
set | Set of string values (MySQL) |
geometry | Spatial/GIS geometry data |
Dialect Awareness
You don't need to worry about type compatibility when switching dialects. DBSketch maps types intelligently — for example, serial in PostgreSQL mode becomes INT AUTO_INCREMENT in MySQL output. Write your DSL once and export to any supported dialect.
Column Settings
Settings go inside [...] after the column type. Multiple settings are separated by commas.
| Setting | Description |
|---|---|
pk | Primary key |
increment | Auto-increment |
not null | NOT NULL constraint |
unique | UNIQUE constraint |
default: value | Default value |
note: 'text' | Column note/comment |
ref: > table.column | Inline relationship (see Relationships) |
Default Values
Default values can be literals, numbers, or SQL expressions:
Table users {
id int [pk, increment]
status varchar(20) [default: 'active']
score int [default: 0]
is_verified boolean [default: false]
created_at timestamp [default: `now()`]
metadata json [default: '{}']
}Use backticks to wrap SQL expressions so they are passed through literally: default: `now()`, default: `gen_random_uuid()`.
WARNING
String defaults must be wrapped in single quotes: default: 'active'. Without quotes, the parser will treat the value as a keyword or expression.
Table Notes
Add a descriptive note to the entire table using Note: inside the table block:
Table users {
id int [pk]
email varchar(255) [not null]
Note: 'Core user accounts table. Each row represents a registered user.'
}Table notes are exported as COMMENT ON TABLE in PostgreSQL or as inline comments in other dialects. See Notes & Table Groups for more details.
Complete Example
Here is a more complex table demonstrating many features together:
// E-commerce order tracking
Table ecommerce.orders [color: #e74c3c] {
id bigserial [pk]
order_number varchar(20) [not null, unique, note: 'Human-readable order ID, e.g. ORD-20240315-001']
customer_id int [not null, ref: > users.id]
status varchar(20) [not null, default: 'pending']
subtotal decimal(12,2) [not null, default: 0]
tax decimal(12,2) [not null, default: 0]
total decimal(12,2) [not null, default: 0]
currency char(3) [not null, default: 'USD']
shipping_address_id int [ref: > addresses.id]
notes text
placed_at timestamp [default: `now()`]
shipped_at timestamp
delivered_at timestamp
created_at timestamp [default: `now()`]
updated_at timestamp [default: `now()`]
indexes {
customer_id
status
placed_at
order_number [unique]
}
Note: 'Customer purchase orders. Status transitions: pending → paid → shipped → delivered.'
}This example showcases schema prefixes, table colors, various column types, default values (both literal and expression), inline relationships, indexes, and a table note — all in a single table definition.