Skip to content

SQL CREATE Statement

Syntax

The CREATE statement in SQL is used to create new database objects such as databases, tables, views, or indexes.

Create a Database

CREATE DATABASE database_name;

Create a Table

CREATE TABLE table_name (
column1 datatype constraint,
column2 datatype constraint,
...
);

Example

-- Create a new database
CREATE DATABASE company;
/* Creates a database named 'company' */
-- Create a new table
CREATE TABLE employees (
id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
department VARCHAR(50),
age INT,
salary DECIMAL(10, 2)
);
/* Creates a table named 'employees' with the following structure:
| id | name | department | age | salary |
|----|------------|------------|-----|----------|
| | | | | |
*/