Home › Developer Tools › SQL Create Table Generator

SQL Create Table Generator

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

  1. Choose the database tab: MySQL, PostgreSQL, SQLite or SQL Server. You can switch at any time; the SQL is rewritten for that dialect.
  2. Name the table and optionally a schema and comment, or start from a template.
  3. 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).
  4. Add indexes for columns you filter or sort by, such as customer_id, placed_at.
  5. 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:

TypeMySQLPostgreSQLSQLiteSQL Server
Small whole numberTINYINT / SMALLINTSMALLINTINTEGERTINYINT / SMALLINT
Integer / big integerINT / BIGINTINTEGER / BIGINTINTEGERINT / BIGINT
Exact decimal (money)DECIMAL(p,s)NUMERIC(p,s)NUMERICDECIMAL(p,s)
Floating pointFLOAT / DOUBLEREAL / DOUBLE PRECISIONREALREAL / FLOAT
True / falseBOOLEANBOOLEANINTEGERBIT
Text with a limitVARCHAR(n)VARCHAR(n)TEXTNVARCHAR(n)
Long textTEXTTEXTTEXTNVARCHAR(MAX)
Date and timeDATETIMETIMESTAMPTEXTDATETIME2
Date and time with zoneTIMESTAMP (stored as UTC)TIMESTAMPTZTEXTDATETIMEOFFSET
UUIDCHAR(36)UUIDTEXTUNIQUEIDENTIFIER
JSON documentJSONJSONBTEXTNVARCHAR(MAX)
Binary dataBLOBBYTEABLOBVARBINARY(MAX)

Constraints at a glance

ConstraintExampleEffect
PRIMARY KEYPRIMARY KEY (id)Unique, not null row identifier; one per table, may span several columns.
NOT NULLemail VARCHAR(255) NOT NULLThe column must always have a value.
UNIQUEsku VARCHAR(40) UNIQUENo two rows may share a value (NULLs are allowed, except in SQL Server, which permits only one).
DEFAULTDEFAULT CURRENT_TIMESTAMPValue used when an INSERT leaves the column out.
CHECKCHECK (price >= 0)Rejects rows where the condition is false.
FOREIGN KEYREFERENCES 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.

Related tools

Database Schema DesignerDesign tables and relationships visually, then export SQL for MySQL, PostgreSQL or SQLite.SQL Formatter & BeautifierFormat, beautify or minify SQL queries for MySQL, PostgreSQL and more.CSV to SQL ConverterConvert CSV to SQL CREATE TABLE and INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server.SQL to ER DiagramPaste CREATE TABLE statements and get an entity-relationship diagram with keys and links.JSON to Excel ConverterTurn JSON into a styled .xlsx spreadsheet; nested arrays become their own linked sheets.JSON to CSVConvert JSON data to CSV for spreadsheets.CSV to JSONConvert CSV data to JSON with live preview.Excel to CSVConvert XLSX spreadsheets to CSV.CSV ViewerOpen a CSV or TSV file as a sortable, filterable table.Excel Viewer (XLSX / XLS)Open XLSX, XLS and ODS spreadsheets in your browser without Excel.Line Ending ConverterConvert text and files between CRLF, LF and CR line endings.Markdown to HTMLConvert Markdown to clean HTML with a live editor.XML to JSONConvert XML to JSON with validation.Text Encoding ConverterDetect and convert text file encodings like UTF-8, UTF-16 and Latin-1.JSON ViewerExplore JSON as a collapsible tree, search keys and values and copy any node's path.TTF to WOFF2 ConverterConvert TTF and OTF fonts to WOFF2 or WOFF and get a ready @font-face CSS snippet.Chmod CalculatorConvert Linux file permissions between checkboxes, octal (755) and symbolic (rwxr-xr-x) notation.JSON to TypeScriptGenerate TypeScript interfaces or types from JSON, with nested types and optional fields.Morse Code TranslatorTranslate text to Morse code and back, then play it as sound or a blinking light, or save a WAV.HTML Table GeneratorBuild HTML tables in an editable grid with styles, header rows, CSV import and live preview.Hex to Text ConverterConvert hex to text and text to hex with UTF-8 support and space, 0x, \x or comma formats.JSON to XML ConverterConvert JSON to well-formed XML with attributes, arrays and pretty print.JSON to YAML ConverterConvert JSON to clean YAML as you type, with indent, quoting and sort options.YAML to JSON ConverterConvert YAML to pretty or minified JSON, with errors pinned to the exact line.HTML to Markdown ConverterTurn HTML or pasted rich text into clean Markdown with tables and live preview.Markdown Table GeneratorBuild Markdown tables in a grid or paste from Excel/CSV, with alignment and preview.JSON ValidatorCheck JSON with the exact line and column of each error, fix tips and one-click auto-fix.Image to Base64Convert images to Base64 data URIs, CSS backgrounds and HTML img tags in your browser.Base64 to ImagePaste a Base64 string or data URI to preview, identify and download the image.JSON CompareCompare two JSON documents and see every added, removed and changed path.Hex to DecimalConvert hex to decimal instantly with steps and signed mode.Decimal to HexConvert decimal to hex instantly with steps and signed mode.Binary to DecimalConvert binary to decimal instantly with steps and signed mode.Decimal to BinaryConvert decimal to binary instantly with steps and signed mode.Two's Complement CalculatorDecimal to two's complement binary and back for 4-64 bits, with invert-and-add-1 steps.XML to CSV ConverterConvert XML to CSV: detects repeating records, flattens nested data, pick your columns.CSV to XML ConverterConvert CSV to well-formed XML with custom root and row names, escaping and pretty print.TOML to JSON ConverterConvert TOML to JSON and JSON to TOML with a full v1.0 parser and clear error lines.JSON to Swift StructTurn JSON into Swift Codable structs with CodingKeys, optionals and nested types.JSON to TOML ConverterConvert JSON to clean TOML with tables, arrays of tables, inline tables and dates.JSONL to JSON ConverterConvert JSON Lines / NDJSON to a JSON array and back, with line-level error reports.Properties to YAML ConverterConvert Java .properties to nested YAML (application.yml) and YAML back to properties.PX to EM ConverterConvert pixels to em using the parent font size, and em back to px, with conversion tables.Query String to JSONConvert URL query strings to JSON with nested brackets and arrays, and JSON back to a query string.REM to PX ConverterConvert CSS rem values to pixels for any root font size, with a quick 0.25–6rem table.SQL to JSON ConverterConvert SQL INSERT statements and dumps into a JSON array of row objects, with CSV export.TSV to CSV ConverterConvert TSV to CSV and back, or between tab, comma, semicolon and pipe, with correct quoting.TypeScript to JavaScriptConvert TypeScript or TSX to clean JavaScript instantly: strip types, keep or compile JSX.XML to YAML ConverterConvert XML to clean YAML with attributes, text nodes, lists and exact error lines.YAML to XML ConverterConvert YAML to pretty, well-formed XML with custom root, attributes and array item tags.Boolean Algebra SimplifierSimplify boolean expressions or minterm lists to minimal SOP and POS with Quine-McCluskey steps.Compare Excel FilesCompare two Excel spreadsheets cell by cell, highlight changes and export a diff report.CSV CleanerClean messy CSV in one click: trim spaces, drop empty rows and columns, fix headers, dedupe.CSV VLOOKUP ToolJoin two CSV or Excel files on a key column like VLOOKUP, with left, inner and full joins.Remove Duplicates in ExcelFind and remove or highlight duplicate rows in XLSX or CSV files by the columns you choose.GeoJSON ViewerView GeoJSON on a map, inspect and edit properties, validate against RFC 7946 and export.GPX ViewerOpen GPX tracks on a map with distance, elevation profile, moving time, speed and splits.JSON Repair ToolFix broken JSON automatically: trailing commas, quotes, comments, truncated data, with a diff.Karnaugh Map SolverSolve 2–6 variable K-maps: click cells or enter minterms to get the minimal SOP or POS with groups.Merge Excel FilesCombine XLSX, XLS and CSV files into one workbook or append all rows into a single sheet.Parquet File ViewerOpen Apache Parquet files in your browser: schema, rows, filters and CSV or JSON export.Query CSV with SQLRun SQL on CSV, Excel, JSON and Parquet files in your browser with DuckDB. Join and export.Online Serial MonitorTalk to Arduino, ESP32 and USB serial devices in your browser: log, send, plot and save.Split Excel FileSplit an Excel sheet into several files by row count or by each value in a column, as ZIP.SQL IN Clause GeneratorTurn a pasted list into a SQL IN ('a','b') clause with quoting, dedupe and 1,000-item chunks.SQL Online CompilerRun SQL queries online on SQLite with sample databases, a result grid, CSV export and .db save.XML to XSD GeneratorGenerate an XML Schema (XSD) from sample XML: types, occurrences, attributes and namespaces.XML ValidatorCheck if XML is well-formed, see the exact line and column of each error and pretty-print it.
See all 129 Data & File Format Converters →