SQL CREATE TABLE

CREATE TABLE defines a new table: its columns, their types, and rules (constraints) that keep the data valid.

Updated December 1, 2026

Syntax

CREATE TABLE table_name (
  id INTEGER PRIMARY KEY,
  column_name TYPE NOT NULL,
  other_column TYPE DEFAULT value
);

Create a table with constraints

A table for loyalty cards. PRIMARY KEY identifies each row, NOT NULL makes a value required, UNIQUE blocks duplicates, DEFAULT fills in a value, and CHECK enforces a rule.

CREATE TABLE loyalty_cards (
  id INTEGER PRIMARY KEY,
  customer_id INTEGER NOT NULL UNIQUE REFERENCES customers(id),
  points INTEGER NOT NULL DEFAULT 0 CHECK (points >= 0),
  tier TEXT NOT NULL DEFAULT 'bronze'
);
INSERT INTO loyalty_cards (customer_id, points) VALUES (1, 120), (2, 40);
INSERT INTO loyalty_cards (customer_id) VALUES (3);

Check the result:

SELECT c.name, l.points, l.tier
FROM loyalty_cards AS l
JOIN customers AS c ON c.id = l.customer_id;
Result on the SQL Café sample data (3 rows)
namepointstier
Ava120bronze
Ben40bronze
Cara0bronze

Cara’s card got the default 0 points and “bronze” tier. Inserting a negative balance, or a second card for the same customer, would be rejected.

Common mistakes

Practice CREATE TABLE interactively

Write real queries in your browser and get instant feedback in the lesson “CREATE TABLE” (Unit 9). New learners can start free from the first lesson.

Frequently asked questions

What data types does SQL have?

Common ones are INTEGER, DECIMAL/NUMERIC for money, TEXT/VARCHAR, DATE, TIMESTAMP and BOOLEAN. Exact names vary by database; SQLite is flexible about types.

How do I change a table after creating it?

Use ALTER TABLE, for example ALTER TABLE drinks ADD COLUMN size TEXT;.

Related SQL tutorials