SQL Tutorial - Create Table


'Create Table' command creates a new table in your database.

Create Table


The 'Create Table' command creates the new table. Along with the table creation, the columns and their datatypes and constraints are also created.

SQL 'Create Table' Syntax


CREATE Table tablename
(
column1 datatype,
column2 datatype,
column3 datatype,
column4 datatype,
column4 datatype, .
.
.
.
.
columnn datatype
)

The Create Table Example


CREATE TABLE Employees
(
EmployeeID smallint NOT NULL,
EmployeeName nvarchar(50) NOT NULL,
DateOfBirth smalldatetime NOT NULL,
DesignationID smallint NULL,
DeptID smallint NULL,
PhoneNo nvarchar(12) NULL,
City nvarchar(50) NOT NULL,
Salary decimal(5, 2) NULL
)

Note: When creating the columns, the data type of the column must be given so that you know what datatype it hold and if it's a non integer, you need to specify the length of the column also. For a complete list of datatypes of SQL Server 2008, see our section link.