In this post explains how to use the CREATE TABLE statement in SQL Server (Transact-SQL) with syntax and examples.
The SQL Server (Transact-SQL) CREATE TABLE statement allows you to create and define a table.
The syntax for the CREATE TABLE statement in SQL Server (Transact-SQL) is:
The name of the table that you wish to create.
The columns that you wish to create in the table. Each column must have a datatype. The column should either be defined as NULL or NOT NULL and if this value is left blank, the database assumes NULL as the default.
Let's look at an example of how to use the CREATE TABLE statement in SQL Server (Transact-SQL).
For example:
This SQL Server CREATE TABLE example creates a table called employees which has 4 columns.
Now the only problem with this CREATE TABLE statement is that you have not defined a primary key for the table in SQL Server. We could modify this CREATE TABLE statement and define the employee_id as the primary key as follows:
By specifying the words, PRIMARY KEY, after the employee_id field, SQL Server will create employee_id as the primary key for the employees table.