SQL CREATE TABLE Statement Builder

Generate a CREATE TABLE SQL statement with columns, types, and constraints

Takes a table name and columns with data types, nullability, primary key, and defaults, then outputs a valid CREATE TABLE statement tuned for MySQL, PostgreSQL, or SQLite dialect syntax. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

How do the dialects differ?

Auto-increment differs the most: MySQL uses AUTO_INCREMENT, PostgreSQL uses SERIAL or GENERATED, and SQLite uses INTEGER PRIMARY KEY AUTOINCREMENT. The builder adjusts the syntax for the dialect you pick.

SQL CREATE TABLE Statement Builder

Writing DDL by hand is error prone, especially across database engines that disagree on auto-increment and type syntax. This builder turns a list of columns into a clean, valid CREATE TABLE statement for MySQL, PostgreSQL, or SQLite, handling primary keys, nullability, defaults, and dialect quirks for you.

How it works

For each column the builder emits name type followed by modifiers in canonical order: a PRIMARY KEY or auto-increment clause, then NOT NULL, then DEFAULT. Auto-increment is dialect specific:

  • MySQL: INT AUTO_INCREMENT PRIMARY KEY
  • PostgreSQL: SERIAL PRIMARY KEY
  • SQLite: INTEGER PRIMARY KEY AUTOINCREMENT

When more than one column is a primary key, it instead appends a composite PRIMARY KEY (a, b) constraint at the end. String and date defaults are wrapped in single quotes, while numeric and keyword defaults such as CURRENT_TIMESTAMP are left bare.

Typical generated output

CREATE TABLE IF NOT EXISTS users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  email VARCHAR(255) NOT NULL,
  username VARCHAR(100) NOT NULL DEFAULT 'anon',
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

The IF NOT EXISTS clause (optional toggle) prevents an error when the table already exists, which is useful when running schema scripts repeatedly in CI or during development.

How dialects differ

The same table definition produces different DDL depending on the target engine:

FeatureMySQLPostgreSQLSQLite
Auto-incrementINT AUTO_INCREMENTSERIAL or INT GENERATED ALWAYS AS IDENTITYINTEGER PRIMARY KEY AUTOINCREMENT
Timestamp defaultDEFAULT CURRENT_TIMESTAMPDEFAULT CURRENT_TIMESTAMPDEFAULT CURRENT_TIMESTAMP
String typeVARCHAR(255)VARCHAR(255) or TEXTTEXT (types are flexible)
Quoted identifiersBackticksDouble quotesEither

PostgreSQL users often prefer TEXT over VARCHAR(n) because PostgreSQL stores them identically and TEXT avoids an arbitrary length cap. SQLite is loosely typed — any column accepts any value regardless of its declared type — so the generated DDL is valid but the type is advisory.

Tips for good schema design

  • Add an auto-incrementing surrogate primary key to every table unless there is a strong natural key.
  • Mark columns NOT NULL by default and add explicit NULL only where absence is meaningful data.
  • Set a DEFAULT CURRENT_TIMESTAMP on created_at columns so the database fills it automatically on insert.
  • Plan your indexes separately after creating the table: CREATE INDEX idx_users_email ON users(email) for any column used in WHERE or JOIN filters.
  • Avoid DEFAULT on a primary key column — auto-increment handles insertion without a default.