PostgreSQL · Command
CREATE TABLE
CREATE TABLE defines a new, initially empty table. It specifies columns, data types, and optional constraints, and can also create temporary, unlogged, typed, or partitioned tables.
Last updated
Syntax
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] table_name ( [ { column_name data_type [ column_constraint [ ... ] ] | table_constraint | LIKE source_table [ like_option ... ] } [, ... ] ] ) [ INHERITS ( parent_table [, ... ] ) ] [ PARTITION BY { RANGE | LIST | HASH } ( { column_name | ( expression ) } [, ... ] ) ] [ WITH ( storage_parameter [= value ] [, ... ] ) ] [ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ] [ TABLESPACE tablespace_name ]In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.
SubscribeRelated
DROP TABLECREATE TYPECREATE INDEXALTER TABLECREATE TABLESPACE