SQL2ER is a command line tool that takes SQL script as input and generates an ER diagram. The parser is written to adopt PostgreSQL syntax. Report Bug · Request Feature
test.sql
create table department (dep_id serial primary key, dep_name varchar(30), createAt timestamptz default now());
create table employee ( employee_id serial primary key, employee_name varchar(30), employee_age int,
dep_id int references department (dep_id) on delete cascade, createAt timestamptz default now());
create table tasks (task_id int, task_name text);
./sql2er-exe test.sql -o erd.svg
Here are 2 ways to use this tool
- Download the binary from release and simply run it.
./sql2er-exe test.sql -o erd.svg
- Build from source:
You can download stack via GHCup.
then simply build and run using below command from the root directory of the project.
stack run -- test.sql -o erd.svg
- Add Changelog
- Add Additional Examples
- Add more parsing functions
- Add more documentation
See the open issues for a full list of proposed features (and known issues).
- The parser is not smart enough to find syntactical errors in the SQL. It will only extract neccecary information for it to generate an ERD.
- ForeignKeyConstraint can only handle a single column and not a list of column.
- The tool is mainly tested and is following postgres version 17 documentation.
- Not able to parse (to ignore)
Create function
statements. If it came acrosscreate function
statement, it will take rest and stop parsing.
- detach
- using ...
- tablespace
- not valid
- validate
- begin/commit
- This tool is inspired by sqldiagram but the tool was created for MySQL and the parser was weak.