CREATE TABLE
AttentionThis page documents an earlier version. Go to the latest (v2.1)version.
Synopsis
The CREATE TABLE
statement creates a new table in a database. It defines the table name, column names and types, primary key, and table properties.
Syntax
Diagram
create_table
table_element
table_column
column_constraint
table_constraints
column_list
Grammar
create_table ::= CREATE TABLE [ IF NOT EXISTS ] table_name
'(' table_element [ ',' table_element ...] ')';
table_element ::= table_column | table_constraints
table_column ::= column_name column_type [ column_constraint ...]
column_constraint ::= PRIMARY KEY
table_constraints ::= PRIMARY KEY '(' column_list ')'
column_list ::= column_name [ ',' column_name ...]
Where
table_name
andcolumn_name
are identifiers (table_name
can be a qualified name).
Semantics
- An error is raised if
table_name
already exists in the specified database unless theIF NOT EXISTS
option is used.
PRIMARY KEY
- Primary key can be defined in either
column_constraint
ortable_constraint
but not in both of them. - Each row in a table is uniquely identified by its primary key.
See Also
DELETE
DROP TABLE
INSERT
SELECT
UPDATE
Other PostgreSQL Statements
当前内容版权归 YugabyteDB 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 YugabyteDB .