Define a new table and its columns.

Defines a new table with its columns, types, constraints, and indexes. The foundation of relational schema design. Choose column types carefully -- changing them later is expensive. Define NOT NULL and primary keys up front where possible.

Compatibility

Filter by Database
SQL CREATE TABLE Compatibility Across Databases
Database System Support Status Since Version Notes
MySQL Native all Engine options available
PostgreSQL Native all Standard + SERIAL
SQL Server Native all Standard + IDENTITY
Oracle Native all Standard + SEQUENCES
SQLite Native all Standard + AUTOINCREMENT

Details

DDL to create a new relational table.

Standard Syntax

CREATE TABLE table_name ( id INT PRIMARY KEY, name VARCHAR(100) NOT NULL );

Version Support

MySQL: Native in all listed versions PostgreSQL: Native in all listed versions SQL Server: Native in all listed versions Oracle: Native in all listed versions SQLite: Native in all listed versions

Per-Database Syntax & Notes

MySQL Native syntax

Engine options available

CREATE TABLE tbl ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT NULL ) ENGINE=InnoDB;

PostgreSQL Native syntax

Standard + SERIAL

CREATE TABLE tbl ( id SERIAL PRIMARY KEY, name TEXT NOT NULL );

SQL Server Native syntax

Standard + IDENTITY

CREATE TABLE tbl ( id INT IDENTITY(1,1) PRIMARY KEY, name NVARCHAR(100) NOT NULL );

Oracle Native syntax

Standard + SEQUENCES

CREATE TABLE tbl ( id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, name VARCHAR2(100) NOT NULL );

SQLite Native syntax

Standard + AUTOINCREMENT

CREATE TABLE tbl ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL );