This blog post shows how to go from an idea SQL schema to a polished ER diagram by using ChatGPT and dbdiagram.io. You’ll get a sample ChatGPT prompt, a working DBML (dbdiagram) schema for a Library Management System, step-by-step screenshots/handoff steps (what to click), tips for customisation, and ideas for extending the system.
If you want to learn about the basics of ER diagram, follow this link:
https://www.gliffy.com/blog/how-to-draw-an-entity-relationship-diagram
1. Start by talking to ChatGPT: decide what diagram you want
Before you write any SQL or draw anything, have a short conversation with ChatGPT (or another assistant) to clarify the scope of your database and which entities you want shown in the ER diagram.
Example:
You: I need an ER diagram for a Library Management System. The diagram should include books, authors, borrowers, transactions, categories, and book-category relationships. Give me the code that I can use in dbdiagram.io to instantly create the diagram.
2. Use a working DBML schema (copy-paste-ready)
Below is the working DBML for the Library Management System. Copy this exactly into dbdiagram.io (choose DBML when creating a new diagram):
// Library Management System (dbdiagram.io compatible)
Enum transaction_status {
Issued
Returned
Overdue
}
Table authors {
author_id int [pk, increment]
name varchar(100) [not null]
biography text
date_of_birth date
}
Table books {
book_id int [pk, increment]
title varchar(200) [not null]
isbn varchar(20) [unique]
published_year int
author_id int [ref: > authors.author_id]
genre varchar(50)
copies_available int [default: 0]
created_at datetime
updated_at datetime
}
Table borrowers {
borrower_id int [pk, increment]
full_name varchar(100) [not null]
email varchar(100) [unique]
phone_number varchar(20)
address varchar(255)
membership_date date
created_at datetime
}
Table transactions {
transaction_id int [pk, increment]
borrower_id int [ref: > borrowers.borrower_id]
book_id int [ref: > books.book_id]
issue_date date
due_date date
return_date date
status transaction_status [default: 'Issued']
notes text
created_at datetime
}
Table categories {
category_id int [pk, increment]
category_name varchar(100) [unique, not null]
}
Table book_categories {
book_id int [pk, ref: > books.book_id]
category_id int [pk, ref: > categories.category_id]
}
3. Import DBML into dbdiagram.io (visualize)
- Open https://dbdiagram.io and sign in or continue as guest.
- Click New Diagram → pick DBML as the language.
- Paste the DBML schema from step 2 into the editor.
- The diagram will render automatically on the right side.
- Make any visual tweaks in the layout panel if needed.
What you’ll see: Entities (tables) with fields, keys, and foreign-key connectors. Hover items to inspect definitions.
You need to sign up for dbdiagram.io in order to export the diagram. You can then export it into png or pdf or as per your necessity.
4. Edit and improve the diagram
- Reorganise layout: use Arrange → Layout to auto-align nodes.
- Add icons or images from the left panel for visual polish.
- If you want to show cardinality (1–*, 1–1), add small text labels near the connectors.
- Export to PNG or SVG for blog inclusion: File → Export As → choose PNG/SVG.
The End Diagram will look something like this

Related Articles
- XAMPP PHP not running on MAC problem?
Fix common issues when PHP doesn’t start properly on macOS using XAMPP. - How to import SQL database using Terminal
Learn how to import SQL databases directly from your terminal instead of phpMyAdmin. - How to compare data in a relationship table with the main table without using more than one loop?
Efficiently compare relational data in PHP without nested loops for better performance. - Converting Excel document into SQL
A step-by-step guide to convert Excel spreadsheets into SQL insert statements easily.


