How to use the ER Diagram from SQL
- 1. Paste your schemaCopy the CREATE TABLE statements from your project or database tool.
- 2. GenerateThe tool reads columns, keys and REFERENCES and draws the diagram.
- 3. DownloadSave the diagram as SVG or PNG for reports and documentation.
What the tool reads from your SQL
- Every
CREATE TABLE, includingIF NOT EXISTSand quoted names with backticks, double quotes or square brackets. - Column names and types, such as
VARCHAR(100)orDECIMAL(10,2). PRIMARY KEYwritten on the column or as a separate line, including composite keys.FOREIGN KEY (...) REFERENCES table(...)lines and inlineREFERENCESon a column.UNIQUEcolumns, marked UK.
Comments (-- and /* */) and INDEX or CHECK lines are skipped. A foreign key normally means one-to-many, drawn ||--o{. If the foreign key column is also unique, it is one-to-one and drawn ||--o|.
Worked example
The sample schema has departments, employees and projects. Generate it and the tool reports 3 tables, 2 relationships and 10 columns:
- employees.dept_id → departments: each department has zero or many employees.
- projects.lead_emp_id → employees: each employee can lead zero or many projects.
employees.email shows as UK because it is UNIQUE, and DECIMAL(10,2) is shown as DECIMAL(10-2) because the diagram language does not allow commas in type names.
Drawing the ER diagram from real SQL is a good way to check a design. Tables with no lines may be missing a foreign key, and a many-to-many link should go through a junction table, such as enrollments(student_id, course_id) between students and courses.
Frequently asked questions
Which SQL dialects work?
Standard CREATE TABLE syntax from MySQL, PostgreSQL, SQL Server and SQLite. Unusual vendor options after the closing bracket are ignored.
Can it read ALTER TABLE ... ADD FOREIGN KEY?
Not yet. Put the foreign key inside the CREATE TABLE statement, or add a REFERENCES clause to the column.
Is my schema uploaded?
No. It is read in your browser and drawn with the open-source Mermaid library from cdnjs.
Is the ER diagram tool free?
Yes, it is free. The first diagram asks for your name and WhatsApp number once, and after that all Uncodemy tools open without asking.