Skip to main content

💬 Community Forum has moved!

Hi dbdiagram.io users, it's been a great journey with you! To have a better focus on our engagement, we are proud to announce: We have moved our forum from Holistics forum to the new site at https://community.dbdiagram.io/!

dbdiagram_forum

New categories will be created and we hope this will allow you to quickly obtain answers for all your queries 😉


🔍 Support Index for Tables

  1. Users can define index using DBML in the code editor
  2. Users can export DBML to SQL with the indexes defined as SQL

There are 3 types of index definitions:

Example 1 with PostgreSQL

  • Index with single field (with index name):
    CREATE INDEX Date on users (created_at)

  • Index with multiple fields (composite index):
    CREATE INDEX on users (created_at, country)

  • Index with an expression:
    CREATE INDEX ON users (lower(name))

  • (bonus) Composite index with expression:

    CREATE INDEX ON users ( country, (lower(name)) )

Indexes {
created_at [name: "Date"]
(created_at, country)
`lower(name)`
(country,`lower(name)`)
(country) [unique]
booking_date [type: btree]
}

Index Settings

  • type: type of index (btree, gin, gist, hash depending on DB), we only accept type Btree and Hash for now.
  • name: name of index
  • unique: unique index

Example 2

Users can define single or multi-column indexes. Example 2 shows a multi-column index.

Table products {
id int [pk]
name varchar
merchant_id int [not null]
price int
status varchar
created_at datetime [default: `now()`]

Indexes {
(merchant_id, status) [name:"product_status"]
id [unique]
}
}

In the visual plane,

Share with us what you think of our Index syntax or any other releases at our new community forum on https://community.dbdiagram.io/!


🚀 Support Default Value

dbdiagram.io now allows default value to your columns! For example, when creating BOOLEAN columns, we commonly give the column a default value (TRUE or FALSE, whatever is appropriate) and make the column NOT NULL. This means, if no other value is given, you can be confident that the column will have a set appropriate value.

Syntax

  • number value starts blank: default: 123 or default: 123.456
  • string value starts with single quotes: default: 'some string value'
  • expression value is wrapped with backtick: default: `now() - interval '5 days'`
  • boolean: default: false

Example 1

Table users {
id integer [primary key]
username varchar(255) [not null, unique]
full_name varchar(255) [not null]
gender varchar(1) [default: 'm']
created_at timestamp [default: `now()`]
rating integer [default: 10]
}

Example 2

Enum job_status {
created
running
done
failure
}

Table jobs {
id integer
status job_status [note: 'Status of a job', default: 'created']
}

Share with us what you think of our dbdiagram.io tool or any other releases at our new community forum on https://community.dbdiagram.io/!


📊 Support Embedded Diagrams

Sharing gets more Awesome! 🤩📤 You can now attach dbdiagram.io into your documents, blogs and websites more efficiently! Zoom and re-arrange your dbdiagram.io to fit your page.

embed_diagram

Example

For Notion, use the url inside the iframe: copy and embed only https://dbdiagram.io/embed/5cf4e1101f6a891a6a658ef9 from <iframe width="560" height="315" src='https://dbdiagram.io/embed/5cf4e1101f6a891a6a658ef9'> </iframe>


🚀 Support Enum Syntax

Good news! You can now view your Enum in your fields!

View your predefined constants of a variable all in one database diagram. 😎

Syntax

Enum header_column {
predefined_1
predefined_2
:
}

Example

Enum orders_status {
created
running
done
failure
}

Table orders {
id int [pk]
user_id int [not null, unique]
status orders_status
created_at varchar [note: "When order created"]
}

When the user hovers the status field in the diagram, there is an auto-display drop-down of all the Enum values.