SQL Server: How to create a table

Introduction:

In this article i will explain how to create a table in SQL Server.

Description:

In previous articles i explained System Databases, and other SQL Server related articles. Now i will explain how to create a table in SQL Server.

Basic Syntax:

create table <table-name>
(
    <column-name> <data-type>,
    <column-name> <data-type>,
    ...
)

Example:

Now we will create a Employee table.

create table Employee
(
    EmpNo int,
    EmpName varchar(20),
    EmpSalary decimal
)

Write the above query and press F5 or click Execute button as shown below.

Now we will get following message at the bottom of the window. 

"Command(s) completed successfully.

This means your table created successfully.

Check:

Now we will check wethere Employee table is create or not? Run the following query so that you will get table related details.

Exec sp_help 'Employee'

In the above query sp_help is a procedure and you are passing Employee table name as parameter. Pass table name in single quotes. After executing the above query you will get table realted full information like table name, columns list, and other details. See the following output you will find table details.