Latest web development tutorials

SQL CREATE TABLE statement

SQL CREATE TABLE statement

CREATE TABLE statement to create a table in the database.

Tables consist of rows and columns, each 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 ),
....
);

column_name parameter specifies the name of the column in the table.

data_type parameter specifies the type of data (such as varchar, integer, decimal, date, etc.) column.

size parameter specifies the maximum length of the column in the table.

Hint: For MS Access, MySQL and SQL Server data types available, please access our complete Data Types Reference Manual .


SQL CREATE TABLE Examples

Now we want to create a table named "Persons" that contains five: PersonID, LastName, FirstName, Address, and City.

We use the following CREATE TABLE statement:

Examples

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

PersonID data type column is int, contains an integer.

LastName, FirstName, Address, and City columns of data type is varchar, contain characters, and the maximum length for these fields is 255 characters.

Empty "Persons" table is as follows:

PersonID LastName FirstName Address City

Tip: You can use the INSERT INTO statement to write data to the empty table.