What is Temporary Table in SQL Server?

Introduction:

In this article i will explain what is Temporary Table in SQL Server.

Description:

In previous articles i explained few sql commands. Now i will explain what is Temporary Table in SQL Server.

Temporary Table is created in tempdb database. Prefix "#" to create temporary table.

Syntax:

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

Following figure shows the list of Temporary Tables present in tempdb before creating the temporary table.

Example:

Create table #Emp
(
    EmpNo int identity(1,1),
    EmpName varchar(20)
)

Following figure shows the list of Temporary Tables present in tempdb after creating the temporary table.

Note:

After restarting the SQL Server, the temporary table is deleted from tempdb database.