Code has been added to clipboard!

SQL CREATE TABLE

Reading time 1 min
Published Aug 9, 2017
Updated Oct 9, 2019

TL;DR – The SQL CREATE TABLE command creates a new table in your database. Each table has a name and is organized into columns and rows. You can define the data held in the column by using the datatype parameter.

The SQL CREATE TABLE syntax

Example
CREATE TABLE mytable (
    column1 datatype,
    column2 datatype,
    column3 datatype,
   ....
);

Copying an existing table

Example
CREATE TABLE mynew_table_name AS
    SELECT column1, column2,...
    FROM myexisting_table_name
    WHERE ....;

An example of creating an SQL table

Example
CREATE TABLE Suppliers (
    SupplierID int,
    FirstName varchar(255),
    LastName varchar(255),
    City varchar(255),
    Country varchar(255) 
);

Note: you can fill the empty table with data later by using the INSERT INTO statement.

The result

ID First_Name Last_Name City Country
Learn SQL
Introduction
Syntax
Data Types
Server Data Types
Commands
Commands List
Wildcards
Constraints
Aggregate Functions
Date Functions
Date Format
Injection
SQL Server Hosting
Views
Auto-incrementation
SQL Operators
AS
AND & OR
IN
BETWEEN
WHERE
GROUP BY
HAVING
ORDER BY
LIKE
NOT
NOT EQUAL
UNION
NULL
NOT NULL
DEFAULT
UNIQUE
FOREIGN KEY
PRIMARY KEY
CHECK
Indexes
ALTER TABLE
CREATE DATABASE
CREATE TABLE
DELETE
DROP
INSERT INTO SELECT
INSERT INTO
SELECT
SELECT DISTINCT
SELECT INTO
SELECT TOP
UPDATE
FULL OUTER JOIN
INNER JOIN
JOIN
LEFT JOIN
RIGHT JOIN
AVG()
COUNT
FIRST
LAST
MAX
MIN()
SUM()
LEN
UCASE
MID
NOW
ROUND
FORMAT
LOWER
CONVERT
ISNULL