7/15/25, 9:31 AM SQL CREATE TABLE Statement
Tutorials Exercises Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
ADVERTISEMENT
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.
[Link] 1/7
7/15/25, 9:31 AM SQL CREATE TABLE Statement
SQL Tutorials
CREATE TABLE
Exercises Example
Services Sign In
HTML CSS
The following JAVASCRIPT
example createsSQL
a table PYTHON JAVA thatPHP
called "Persons" HOW
contains fiveTO [Link]
columns: C
PersonID, LastName, FirstName, Address, and City:
ADVERTISEMENT
Example Get your own SQL Server
CREATE TABLE Persons (
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
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.
ADVERTISEMENT
[Link] 2/7
7/15/25, 9:31 AM SQL CREATE TABLE Statement
Tutorials Exercises Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
ADVERTISEMENT
Create Table Using Another Table
A copy of an existing table can also be created using CREATE TABLE .
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 "TestTable" (which is a copy of the
"Customers" table):
Example
CREATE TABLE TestTable AS
SELECT customername, contactname
[Link] 3/7
7/15/25, 9:31 AM SQL CREATE TABLE Statement
FROM customers;
Tutorials Exercises Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
ADVERTISEMENT
?
Exercise
What is the primary purpose of the SQL CREATE TABLE statement?
To create a new table in a database
To insert data into a table
To join a table
To delete a table from a database
Submit Answer »
❮ Previous Next ❯
Track your progress - it's free! Sign Up Log in
ADVERTISEMENT
[Link] 4/7
7/15/25, 9:31 AM SQL CREATE TABLE Statement
Tutorials Exercises Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
ADVERTISEMENT
[Link] 5/7
7/15/25, 9:31 AM SQL CREATE TABLE Statement
COLOR PICKER
Tutorials Exercises Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
PLUS SPACES
GET CERTIFIED FOR TEACHERS
FOR BUSINESS CONTACT US
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
[Link] Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial
[Link] 6/7
7/15/25, 9:31 AM SQL CREATE TABLE Statement
Top References
Tutorials Exercises Services Sign In
HTML Reference
HTML
CSS CSS ReferenceSQL
JAVASCRIPT PYTHON JAVA PHP HOW TO [Link] C
JavaScript Reference
SQL Reference
ADVERTISEMENT Python Reference
[Link] Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference
Top Examples Get Certified
HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
[Link] Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate
FORUM ABOUT ACADEMY
W3Schools is optimized for learning and training. Examples might be simplified to improve
reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot
warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of use,
cookie and privacy policy.
Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by [Link].
[Link] 7/7