SQL CREATE TABLEStatements
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 each table must have a table name.
SQL CREATE TABLE Syntax
(
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 (e.g., varchar, integer, decimal, date, etc.).
The size parameter specifies the maximum length of the column in the table.
Tip:For data types available in MS Access, MySQL, and SQL Server, please visit our completeData 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
(
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
The PersonID column has a data type of int, which holds integers.
The LastName, FirstName, Address, and City columns have a data type of varchar, which contains 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.
Other Extensions