Skip to main content
Back to Dev generators

Dev

Mock Postgres Table Schema Generator

Reading a CREATE TABLE statement is often the fastest way to understand a data model, but writing a realistic one from scratch — with the right column types, constraints, defaults, and foreign keys — takes longer than it should when you just need an example. This tool generates a sample PostgreSQL CREATE TABLE statement for one of five tables: users, orders, products, sessions, or invoices. There are no inputs. Each table is pre-defined with columns appropriate to its domain. Users has email (VARCHAR UNIQUE), name, is_active (BOOLEAN DEFAULT true), and created_at (TIMESTAMPTZ DEFAULT now()). Orders has a REFERENCES users(id) foreign key, a NUMERIC total, and a status with a DEFAULT. Products uses TEXT[] for tags. Sessions and invoices include foreign key references and a date or timestamp column. Every table gets an id SERIAL PRIMARY KEY. Copy the output into a psql session, a migration file, or documentation. Adapt the table and column names to your own domain. The NUMERIC(10,2) type is appropriate for monetary values; avoid FLOAT for money because of floating-point precision errors.

Read the complete guide — 4 min read

How to use

  1. Choose your options above
  2. Click Generate
  3. Copy your result

Detailed instructions

  1. Click Generate to produce a table schema.
  2. Copy the SQL into a migration or console.
  3. Adapt the columns to your data model.
  4. Run it after tailoring to your needs.

Use Cases

  • Learning SQL table syntax
  • Seeding a test database schema
  • Documenting a data model
  • Demoing PostgreSQL DDL
  • Testing a migration tool

Tips

  • SERIAL makes an auto-increment id.
  • Use REFERENCES for foreign keys.
  • NUMERIC suits money values.
  • Adapt the schema to your data.

FAQ

what tables can the generator produce

It picks one of five at random: users (with email, name, is_active, created_at), orders (with user_id FK, total, status), products (with price and a TEXT[] tags column), sessions (with user_id FK, token, expires_at), and invoices (with order_id FK, amount, paid, due_date). Each table always includes an id SERIAL PRIMARY KEY.

what is a serial primary key in postgres

SERIAL is a PostgreSQL shorthand that creates an integer column backed by a sequence, auto-incrementing for each new row. It is equivalent to defining the column as INTEGER with a DEFAULT nextval(sequence). For new schemas, GENERATED ALWAYS AS IDENTITY is the modern equivalent, but SERIAL remains widely used and understood.

why use numeric(10,2) instead of float for monetary values

FLOAT stores values as binary floating-point, which cannot represent decimal fractions like 0.10 exactly, causing rounding errors in financial calculations. NUMERIC (also called DECIMAL) stores values at exact precision, making it the correct type for monetary amounts. NUMERIC(10,2) means up to 10 significant digits with exactly 2 decimal places.

can I run the generated statement directly against postgres

The syntax is valid PostgreSQL DDL, but the tables reference each other — for example, orders references users(id) — so if you run an orders CREATE TABLE without the users table existing first, it will fail. Run the statements in dependency order, or adapt the schema to your own data model.

You might also like

Popular tools from other categories that share themes with this one.

Try these next

More free tools from other corners of the catalog, picked by shared themes.