Introduction:

In this article we will explain what is temporary table in SQL Server is or how to create temporary table in SQL server with example.

Description:

SQL Server provides the concept of temporary table which helps the developer to many ways. Temporary tables can be created at run-time and can do all kinds of operations that a normal table can do. But, based on the table types, the scope is limited.  These temporary tables are created inside tempdb database.

There are two types of temp tables based on the behavior and scope.

1. Local Temp table

2. Global Temp table 


LOCAL TEMP TABLE

 

Local temp tables are only available at current connection to the user. It is automatically deleted when user disconnects from instances Local temporary table name is stared with hash ("#") sign.

CREATE TABLE #localtemp (  
EmployeeId int, 
EmployeeName varchar (50), 
EmployeeEmail varchar (150), 
EmployeeAddress varchar (150))



  • GLOBAL TEMP TABLE

  • Global Temporary tables name starts with a double hash ("##"). Once this table is created by a connection, like a permanent table it is always available to any user by any connection. It can only be deleted once all connections have been closed.
  •  
CREATE TABLE ##globaltemp (  
EmployeeId int, 
EmployeeName varchar (50), 
EmployeeEmail varchar (150), 
EmployeeAddress varchar (150) );  



I hope this article will help to you.

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

you may also like