WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL CREATE TABLE Statement



SQL CREATE TABLE statement

CREATE TABLE statement is used 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 ),
....
);
The

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

The

data_type parameter specifies the data type of the column (for example, varchar, integer, decimal, date, and so on).

The

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

Tip: To learn about the data types available in MS Access, MySQL, and SQL Server .


SQL CREATE TABLE instance

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)
);

PersonID column is int and contains integers.

LastName, FirstName, Address, and City columns are varchar, contain 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 to an empty table.