The Wayback Machine - https://web.archive.org/web/20261201070825/https://www.geeksforgeeks.org/sql/sql-create-table/

SQL CREATE TABLE

Last Updated : 27 Nov, 2026

The CREATE TABLE statement in SQL is used to define a new table in a database. It specifies the table structure including column names and their data types.

  • Used to create a new table in a database.
  • Defines column names and their data types.
  • Helps in organizing and storing data systematically.

Syntax:

CREATE TABLE table_name
(
column_1 datatype ,
column_2 datatype,
.
.
column_N datatype(size)
);
  • table_name: The name you assign to the new table.
  • column_1, column_2, ... : The names of the columns in the table.
  • datatype: Defines the data type and size of each column.

Working

Query:

CREATE TABLE customer(
customer_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
country VARCHAR(50),
age INT CHECK (age >= 0 AND age <= 99),
phone INT(10)
);

Output:

sql_output

Inserting Data into the Table

After creating the table, you can use INSERT INTO command to add data into it. Here is how to add some sample records into the customer table.

Query:

INSERT INTO customer (customer_id, first_name, last_name, country, age, phone)
VALUES
(1, 'Luca', 'Bianchi', 'Italy', 23, 'xxxxxxxxxx'),
(2, 'Aiko', 'Tanaka', 'Japan', 21, 'xxxxxxxxxx'),
(3, 'Carlos', 'Gomez', 'Spain', 24, 'xxxxxxxxxx'),
(4, 'Sofia', 'MÞller', 'Germany', 22, 'xxxxxxxxxx'),
(5, 'Ethan', 'Johnson', 'USA', 25, 'xxxxxxxxxx');

Output:

50

Note: If you are working with a large amount of data, consider using bulk inserts or importing data from external files to optimize performance.

Create Table from Existing Table

The CREATE TABLE AS SELECT statement creates a new table using selected columns and data from an existing table.

Syntax:

CREATE TABLE new_table_name AS
SELECT column_1, column_2, ...
FROM existing_table_name;

Query:

CREATE TABLE customer_subset AS
SELECT customer_id, first_name
FROM customer;

Output:

51

Note: We can use * instead of column name to copy whole table to another table.

Tips for Using CREATE TABLE

1. Defining constraints such as NOT NULL, UNIQUE and DEFAULT while creating a table.
2. Using IF NOT EXISTS to avoid errors if the table already exists.
3. Using DESC table_name; to view the table structure after creation.

Comment