SQL CREATE TABLE Statement
SQL CREATE TABLE Statement
The CREATE TABLE statement is used to create a table in a database.
A table consists of rows and columns, and every table must have a table name.
SQL CREATE TABLE syntax
CREATE TABLE
table_name
(
column_name1 data_type
(
size
),
column_name2 data_type
(
size
),
column_name3 data_type
(
size
),
....
);
The column_name parameter specifies the name of the column in the table.
The data_type parameter specifies the data type of the column (such as varchar, integer, decimal, date, and so on).
The size parameter specifies the maximum length of the column in the table.
**Tip:** To learn about the data types available in MS Access, MySQL, and SQL Server, visit our complete Data Types Reference Manual。
SQL CREATE TABLE example
Now we want to create a table named "Persons" with five columns: PersonID, LastName, FirstName, Address, and City.
We use the following CREATE TABLE statement:
Example
CREATE TABLE Persons
(
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
The PersonID column has a data type of int, containing integers.
The LastName, FirstName, Address, and City columns have a data type of varchar, containing characters, and the maximum length of these fields is 255 characters.
The empty "Persons" table looks like this:
| PersonID | LastName | FirstName | Address | City |
|---|---|---|---|---|
**Tip:** You can use the INSERT INTO statement to write data into an empty table.