0% found this document useful (0 votes)
183 views

SQL CREATE TABLE Statement

The SQL CREATE TABLE statement is used to create a new table in a database. It specifies the table name, column names, and column data types. An example shows how to create a table called Persons with columns for ID, name, address, and city.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
183 views

SQL CREATE TABLE Statement

The SQL CREATE TABLE statement is used to create a new table in a database. It specifies the table name, column names, and column data types. An example shows how to create a table called Persons with columns for ID, name, address, and city.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

3/21/2020 SQL CREATE TABLE Statement

w3schools.com

  HTML CSS MORE   

 Trendsetters Feed
not Jony Ive Wash your hands as though you’ve been touching an Android
 @JonyIveParody • 3d View device or Windows PC all day. #coronavirus https://t.co/ei32BvL... 
image

Follow  36  249 Reply Here 140 Send

SQL CREATE TABLE Statement


❮ Previous Next ❯

The SQL CREATE TABLE Statement


The CREATE TABLE statement is used to create a new table in a database.

Syntax

CREATE TABLE table_name (


column1 datatype,
column2 datatype,
column3 datatype,
....
);

The column parameters specify the names of the columns of the table.

The datatype parameter specifies the type of data the column can hold (e.g. varchar,
integer, date, etc.).

Tip: For an overview of the available data types, go to our complete Data Types
Reference.

https://www.w3schools.com/sql/sql_create_table.asp 1/9
3/21/2020 SQL CREATE TABLE Statement

SQL CREATE TABLE Example


The following example creates a table called "Persons" that contains five columns:
PersonID, LastName, FirstName, Address, and City:

Example
CREATE TABLE Persons (
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);

Try it Yourself »

The PersonID column is of type int and will hold an integer.

The LastName, FirstName, Address, and City columns are of type varchar and will hold
characters, and the maximum length for these fields is 255 characters.

The empty "Persons" table will now look like this:

PersonID LastName FirstName Address City

Tip: The empty "Persons" table can now be filled with data with the SQL INSERT INTO
statement.

Create Table Using Another Table


A copy of an existing table can also be created using CREATE TABLE.

https://www.w3schools.com/sql/sql_create_table.asp 2/9
3/21/2020 SQL CREATE TABLE Statement

The new table gets the same column definitions. All columns or specific columns can be
selected.

If you create a new table using an existing table, the new table will be filled with the
existing values from the old table.

Syntax

CREATE TABLE new_table_name AS


SELECT column1, column2,...
FROM existing_table_name
WHERE ....;

The following SQL creates a new table called "TestTables" (which is a copy of the
"Customers" table):

Example

CREATE TABLE TestTable AS


SELECT customername, contactname
FROM customers;

Try it Yourself »

Test Yourself With Exercises

Exercise:
Write the correct SQL statement to create a new table called Persons .

https://www.w3schools.com/sql/sql_create_table.asp 3/9
3/21/2020 SQL CREATE TABLE Statement

CREATE TABLE PERSONS (


PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);

Submit Answer »

Start the Exercise

❮ Previous Next ❯

https://www.w3schools.com/sql/sql_create_table.asp 4/9
3/21/2020 SQL CREATE TABLE Statement

Bi-
directional
Email
Sync
Nylas APIs

Power your
application with bi-
directional sync
and send from any
inbox in the world.

LEARN MORE

COLOR PICKER

HOW TO

Tabs
Dropdowns
Accordions
Side Navigation
Top Navigation

https://www.w3schools.com/sql/sql_create_table.asp 5/9
3/21/2020 SQL CREATE TABLE Statement

Modal Boxes
Progress Bars
Parallax
Login Form
HTML Includes
Google Maps
Range Sliders
Tooltips
Slideshow
Filter List
Sort List

SHARE

 

CERTIFICATES

HTML
CSS
JavaScript
SQL
Python
PHP
jQuery
Bootstrap
XML

Read More »

https://www.w3schools.com/sql/sql_create_table.asp 6/9
3/21/2020 SQL CREATE TABLE Statement

Spin up
CockroachDB
on AWS

CockroachDB
Database
Management on
AWS - Try it Free

Bi-directional Email S

Power your application with bi-dir


sync and send from any inbox in
world.
Nylas APIs

https://www.w3schools.com/sql/sql_create_table.asp 7/9
3/21/2020 SQL CREATE TABLE Statement

___

 
Sponsored

REPORT ERROR

PRINT PAGE

FORUM

ABOUT

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
jQuery Tutorial
Java Tutorial
C++ Tutorial

Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference

https://www.w3schools.com/sql/sql_create_table.asp 8/9
3/21/2020 SQL CREATE TABLE Statement

HTML Colors
jQuery Reference
Java Reference
Angular Reference

Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
jQuery Examples
Java Examples
XML Examples

Web Certificates
HTML Certificate
CSS Certificate
JavaScript Certificate
SQL Certificate
Python Certificate
jQuery Certificate
PHP Certificate
Bootstrap Certificate
XML Certificate

Get Certified »

W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading
and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we
cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our
terms of use, cookie and privacy policy. Copyright 1999-2020 by Refsnes Data. All Rights Reserved.
Powered by W3.CSS.

https://www.w3schools.com/sql/sql_create_table.asp 9/9

You might also like