← All languages
SQL keyword of the day
Random

CREATE TABLE

Create a new table in the database.

Description

The CREATE TABLE statement defines a new table in the database with a specified name and column definitions. Each column definition includes a name, data type, and optional constraints such as PRIMARY KEY, NOT NULL, UNIQUE, DEFAULT, and FOREIGN KEY. You can also define table-level constraints. CREATE TABLE is a data definition language (DDL) statement. Using IF NOT EXISTS prevents an error if the table already exists.

Arguments

NameDescriptionOptional
table_name The name for the new table. No
column_definitions One or more column definitions including name, data type, and optional constraints. No

Example

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