AI Hints
Home›PostgreSQL Tutorial›Creating Tables
PostgreSQL · Lesson 16 of 120

CREATE TABLE

Your own tables.

⏱ 2 min read▶ Video at 13:09🎓 Free
Watch this lesson in the PostgreSQL courseWatch on YouTube ↗Full PostgreSQL course

Riverside Books wants to run author events, like book signings. That needs a new table. Create table names the table, and lists each column with its type.

  • Author events
  • New table
  • Columns + types

An events table

Each line is a column, then its type. Title is text, starts at is a timestamp with time zone, and seats is an integer. Then we add one event, and select it. Run it. Our first table, with one row.

query.sqlsql
CREATE TABLE events (
  title     text,
  starts_at timestamptz,
  seats     integer
);

INSERT INTO events VALUES ('Signing: Mira Hale', '2026-03-14 18:00+00', 40);
SELECT * FROM events;
Output
CREATE TABLE
INSERT 0 1
       title        |       starts_at        | seats
--------------------+------------------------+-------
 Signing: Mira Hale | 2026-03-14 18:00:00+00 |    40
(1 row)

Naming tips

Use lower case names, with underscores. Plural or singular table names both work, just be consistent. Avoid names that need quotes. And give every table a primary key, which is next.

keyvalue
Casesnake_case
Tablesconsistent plural
Quotesavoid
Alwaysa primary key

Summary

Create table defines columns and types, and insert adds rows. Next, ID columns that number themselves.

Key takeaways
  • CREATE TABLE
  • Columns
  • Types
Next up: Identity Columns — IDs that count themselves