SQL CREATE TABLE
Statement
SQL CREATE TABLE Statement
The CREATE TABLE statement is used to create a table in the database.
A table consists of rows and columns, and each table must have a table name.
SQL CREATE TABLE Syntax
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.
Note: For information on available data types in MS Access, MySQL, and SQL Server, please visit our complete Data Types Reference.
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
The data type of the PersonID column is int, which contains integers.
The data type of the LastName, FirstName, Address, and City columns is 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 |
---|---|---|---|---|
Note: You can use the INSERT INTO statement to insert data into an empty table.