How the SQL CREATE TABLE Generator works
Every change you make is turned into a CREATE TABLE statement straight away. Names are quoted for the chosen
dialect ([brackets], "double quotes" or `backticks`), or only when needed if you untick
Quote all names. The type list shows the types of the selected database, and the length or precision field is checked
against the type: NVARCHAR needs a length or MAX, DECIMAL takes precision and scale
such as 10,2, and types like INT take none.
Identity columns are written as IDENTITY(1, 1) for SQL Server, GENERATED ALWAYS AS IDENTITY for
PostgreSQL and AUTO_INCREMENT for MySQL. Primary key and identity columns are always NOT NULL. One
primary key column is marked inline; several are combined into a CONSTRAINT PK_table PRIMARY KEY (...) line.
On SQL Server, columns that allow nulls are written with an explicit NULL. Problems such as a missing length or
two identity columns are explained in the status line. The statement is not run against any database.
How to use the SQL CREATE TABLE Generator
- Choose the dialect, then enter the table name and, if you use one, the schema (for example dbo or public).
- For each column enter a name, pick a type, and fill in the length or precision where the type needs one, such as 255 for NVARCHAR or 10,2 for DECIMAL.
- Tick Primary key, NOT NULL, Identity (Auto increment in MySQL) or Unique as needed, and enter a default value if the column has one.
- Use Add column, Up, Down and Remove to change the column list, or select Load example to start from a sample table.
- Copy the CREATE TABLE statement or download it as a .sql file. Any problem, such as a missing length, is explained just above the output.
Example
Table Customers in schema dbo on SQL Server, with CustomerId INT (primary key, identity),
Email NVARCHAR 255 (NOT NULL, unique), CreditLimit DECIMAL 10,2 (NOT NULL, default 0) and
Status VARCHAR 20 (NOT NULL, default active):
CREATE TABLE [dbo].[Customers] (
[CustomerId] INT IDENTITY(1, 1) NOT NULL PRIMARY KEY,
[Email] NVARCHAR(255) NOT NULL UNIQUE,
[CreditLimit] DECIMAL(10, 2) NOT NULL DEFAULT 0,
[Status] VARCHAR(20) NOT NULL DEFAULT 'active'
);
Switching the dialect to PostgreSQL with schema public changes it to:
CREATE TABLE "public"."Customers" (
"CustomerId" INTEGER GENERATED ALWAYS AS IDENTITY NOT NULL PRIMARY KEY,
"Email" VARCHAR(255) NOT NULL UNIQUE,
"CreditLimit" NUMERIC(10, 2) NOT NULL DEFAULT 0,
"Status" VARCHAR(20) NOT NULL DEFAULT 'active'
);
Common use cases
- Sketching a new table during design without remembering the exact syntax for each database.
- Writing the same table for SQL Server, PostgreSQL and MySQL by switching the dialect; column types are converted to the closest equivalent.
- Creating a table for test data before generating INSERT statements.
- Learning how identity columns, composite primary keys and defaults are written in each dialect.
Common errors and how to fix them
- Enter a table name / Add at least one column
- The generator needs both before it can produce a statement. Fill in the table name and at least one column definition.
- Only one column per table can be an identity / auto increment column
- You have marked more than one column as auto-incrementing, which no supported database allows. Keep the flag on the single surrogate key column.
- Unexpected text after a quoted part of the table name
- The table name mixes quoted and unquoted parts, for example a stray bracket or bracketed schema. Enter the plain name, or a schema-qualified name such as sales.orders, and let the tool apply the dialect's quoting.
- A column name is rejected as a reserved word
- The name collides with a SQL keyword. Rename it, or rely on the dialect's identifier quoting, keeping in mind that quoted names must then be quoted everywhere they are used.
Frequently asked questions
How are identity columns written?
SQL Server uses IDENTITY(1, 1), PostgreSQL uses GENERATED ALWAYS AS IDENTITY and MySQL uses AUTO_INCREMENT. The option is only available for integer types, only one column per table can use it, and in MySQL the column must also be a primary key or unique.
How do default values work?
Numbers, NULL, TRUE, FALSE, CURRENT_TIMESTAMP-style keywords, quoted strings and expressions with parentheses such as NEWID() or now() are used as written. Any other text is treated as a string and quoted for you, so active becomes 'active'. For SQL Server, TRUE and FALSE are written as 1 and 0.
What happens with more than one primary key column?
A single primary key column gets PRIMARY KEY on its line. When several columns are ticked, a CONSTRAINT PK_TableName PRIMARY KEY (...) line is added at the end instead.
What happens to my columns when I change the dialect?
Each column keeps its name and settings, and its type is changed to the closest type in the new dialect, for example NVARCHAR to VARCHAR, DATETIME2 to TIMESTAMP or BIT to BOOLEAN. Check the types afterwards, because some types have no exact equivalent.
Does the generator create the table in my database?
No. It only writes the CREATE TABLE statement for you to copy. It never connects to a database or runs SQL, and nothing you enter is sent to our server.