How to use the Database Schema Designer
- 1. Write your tablesOne table per block: column name, type and options like pk, not null, unique, default and > table.column.
- 2. Pick a databaseMySQL/MariaDB, PostgreSQL, SQLite or SQL Server.
- 3. DesignSee the ER diagram and copy or download schema.sql.
The format
Each table is written as table students { … } with one column per line, for example dept_id int > departments.id for a foreign key. Mark keys with pk (several pk columns make a composite key) and auto-numbering with increment. Other options are not null, unique and default (numbers, 'text', true/false, today or now). Types map to each database's own types: varchar becomes NVARCHAR in SQL Server, json becomes JSONB in PostgreSQL, and booleans become INTEGER in SQLite. Tables are ordered so referenced tables come first, every foreign key gets an index, and circular references are added afterwards with ALTER TABLE.
Worked example
The sample models a college: departments, students, courses and enrolments. Enrolments has a composite key on (student_id, course_id). That's 4 tables, 15 columns and 3 foreign keys, created in the order departments → students → courses → enrolments. For MySQL the enrolments table ends with PRIMARY KEY (student_id, course_id) and two FOREIGN KEY lines, and enrolled_on DATE DEFAULT (CURRENT_DATE) uses MySQL 8's expression-default syntax.
How we checked the SQL
- We checked the sample and 25 random schemas.
- Every SQLite script ran in SQLite with foreign keys on.
- Every PostgreSQL script parsed with pglast, which uses PostgreSQL's own parser.
- The MySQL and SQL Server scripts parsed with sqlglot.
- Check the MySQL and SQL Server output in your own database before running it on real data; parsing isn't the same as running.
Frequently asked questions
Can I import an existing database?
Not yet. Write the tables in the simple format; it's usually quicker than it sounds.
Why an index on every foreign key?
Databases don't always index foreign keys automatically, and joins on unindexed keys get slow as tables grow.
Is the database schema designer free?
Yes. You can open the database schema designer, load files and set every option without signing up. When you design a schema for the first time, we ask once for your name and WhatsApp number; after that it, and every other Uncodemy tool, opens straight away.