SQL Server: How to create a table

 SQL Server     sbo     Updated on Sep 05, 2013     VIKRAM     448   

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.

  Related Articles
Java Script: Create/Insert rows dynamically to HTML Table and Remove/Delete rows from HTML Table
Java Script: Create HTML Table dynamically
SQL Server: Delete record from parent table when there is Foreign Key relation between parent and child tables
SQL Server: NOT NULL Constraint
SQL Server: Temporary Table
SQL Server: How to rename a column and How to rename a table
SQL Server: How to add a column to table and How to delete a column from table
ASP.Net: ListView Basics - ItemDeleting
  Recent Articles
Java Script: Create/Insert rows dynamically to HTML Table and Remove/Delete rows from HTML Table
Java Script: Create HTML Table dynamically
SQL Server: Delete record from parent table when there is Foreign Key relation between parent and child tables
SQL Server: NOT NULL Constraint
SQL Server: Temporary Table
SQL Server: How to rename a column and How to rename a table
SQL Server: How to add a column to table and How to delete a column from table
ASP.Net: ListView Basics - ItemDeleting