Fill in a simple form and get a correct CREATE TABLE statement for MySQL, PostgreSQL, SQLite or SQL Server. Set each column's type, length, primary key, NOT NULL, UNIQUE, auto increment, default, CHECK rule and foreign key, add indexes and comments, and the SQL updates as you type, with warnings for common mistakes.
Last updated:
Columns
PK primary key · NN not null · UQ unique · AI auto increment
Indexes
Options
CREATE TABLE statement
Advertisement
Advertisement
How to use the SQL Create Table Generator
Choose the database tab: MySQL, PostgreSQL, SQLite or SQL Server. You can switch at any time; the SQL is rewritten for that dialect.
Name the table and optionally a schema and comment, or start from a template.
Add columns: set a name, type and length, tick PK, NN (not null), UQ (unique) or AI (auto increment), and add a default, CHECK rule or foreign key reference like users(id).
Add indexes for columns you filter or sort by, such as customer_id, placed_at.
Review the notes under the output, then copy the SQL or download it as a .sql file.
Data types in each database
The generator lets you pick a portable type and writes the native type of the selected database:
Type
MySQL
PostgreSQL
SQLite
SQL Server
Small whole number
TINYINT / SMALLINT
SMALLINT
INTEGER
TINYINT / SMALLINT
Integer / big integer
INT / BIGINT
INTEGER / BIGINT
INTEGER
INT / BIGINT
Exact decimal (money)
DECIMAL(p,s)
NUMERIC(p,s)
NUMERIC
DECIMAL(p,s)
Floating point
FLOAT / DOUBLE
REAL / DOUBLE PRECISION
REAL
REAL / FLOAT
True / false
BOOLEAN
BOOLEAN
INTEGER
BIT
Text with a limit
VARCHAR(n)
VARCHAR(n)
TEXT
NVARCHAR(n)
Long text
TEXT
TEXT
TEXT
NVARCHAR(MAX)
Date and time
DATETIME
TIMESTAMP
TEXT
DATETIME2
Date and time with zone
TIMESTAMP (stored as UTC)
TIMESTAMPTZ
TEXT
DATETIMEOFFSET
UUID
CHAR(36)
UUID
TEXT
UNIQUEIDENTIFIER
JSON document
JSON
JSONB
TEXT
NVARCHAR(MAX)
Binary data
BLOB
BYTEA
BLOB
VARBINARY(MAX)
Constraints at a glance
Constraint
Example
Effect
PRIMARY KEY
PRIMARY KEY (id)
Unique, not null row identifier; one per table, may span several columns.
NOT NULL
email VARCHAR(255) NOT NULL
The column must always have a value.
UNIQUE
sku VARCHAR(40) UNIQUE
No two rows may share a value (NULLs are allowed, except in SQL Server, which permits only one).
DEFAULT
DEFAULT CURRENT_TIMESTAMP
Value used when an INSERT leaves the column out.
CHECK
CHECK (price >= 0)
Rejects rows where the condition is false.
FOREIGN KEY
REFERENCES customers (id)
Value must exist in the parent table; ON DELETE decides what happens to children.
Tips for good tables
Use DECIMAL for money, never FLOAT: binary floating point cannot store values like 0.10 exactly.
Store times in UTC with a time-zone-aware type (TIMESTAMPTZ, DATETIMEOFFSET) and convert for display.
Index foreign keys and frequent filters. A composite index such as (customer_id, placed_at) serves queries that filter by the first column and sort by the second.
Keep names lowercase snake_case and avoid reserved words like order, user or group, which need quoting in every query.
Choose utf8mb4 in MySQL; the older utf8 (utf8mb3) cannot store emoji and many CJK characters.
Frequently asked questions
What is the basic syntax of CREATE TABLE?
CREATE TABLE table_name (column_name data_type [constraints], ..., [table constraints]); Each column has a name and a type, optionally followed by NOT NULL, DEFAULT, UNIQUE, PRIMARY KEY or CHECK. Table-level constraints such as a composite PRIMARY KEY (a, b) or FOREIGN KEY (col) REFERENCES other_table (id) come after the columns.
How do I make an auto-increment primary key?
Tick PK and AI on an integer column. MySQL gets id BIGINT NOT NULL AUTO_INCREMENT, PostgreSQL gets GENERATED BY DEFAULT AS IDENTITY (preferred over SERIAL since version 10), SQL Server gets IDENTITY(1,1), and SQLite gets INTEGER PRIMARY KEY AUTOINCREMENT.
How do I add a foreign key?
Type the referenced table and column in the References field, for example customers(id), and choose an ON DELETE action. The generator adds a named CONSTRAINT fk_table_column FOREIGN KEY (...) REFERENCES customers (id). The referenced table must already exist and its column must be a primary key or unique, with the same data type.
What is the difference between VARCHAR and TEXT?
VARCHAR(n) stores up to n characters and the limit is enforced; it can be indexed fully and given a default. TEXT has no practical length limit. In PostgreSQL both perform the same; in MySQL TEXT columns cannot have a plain literal default and need an index prefix length; in SQLite both are simply TEXT.
Why does SQLite show TEXT for dates and INTEGER for booleans?
SQLite has only five storage classes (NULL, INTEGER, REAL, TEXT and BLOB). Dates are normally stored as ISO 8601 text like 2026-10-20 14:30:00, which sorts correctly and works with SQLite's date functions, and booleans are stored as 0 and 1.
Does IF NOT EXISTS work in every database?
MySQL, PostgreSQL and SQLite support CREATE TABLE IF NOT EXISTS. SQL Server does not, so the generator wraps the statement in IF OBJECT_ID(N'table', N'U') IS NULL. DROP TABLE IF EXISTS is supported by all four (SQL Server since 2016).
Are CHECK constraints enforced?
Yes in PostgreSQL, SQLite, SQL Server and MySQL 8.0.16 or later. Older MySQL versions parse CHECK clauses but silently ignore them, and MariaDB enforces them from 10.2.1.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.