SQL CREATE TABLE Statement
The CREATE TABLE statement in SQL is used to create a table in a database.
Syntax for CREATE TABLE in SQL
CREATE TABLE table_name
(
column1 data_type(size),
column2 data_type(size),
column3 data_type(size),
……
……
);
Here table_name is the name of the table. Column1, Column2, Column3 are the names of the columns of the table. The data_type specifies what type of data the column can hold in the table and the maximum length of the column specified in the size parameter.
We will see the available data types in SQL Data Types tutorial.
Below is the example for CREATE TABLE Statement in SQL
CREATE TABLE Employee
(
Id int,
FirstName varchar(255),
LastName varchar(255),
DateOfBirth datetime
);
Above SQL statement creates a database table named Employee.
Here Id, FirstName, LastName, DateOfBirth are the names of the columns of the table Employee. The Id column is of type int and will hold an integer. FirstName, LastName are the type of varchar and will store string with the maximum length of 255 . DateOfBirth column will hold the data in Date format.
0 comments:
Post a Comment