Pages - Menu

Thursday, December 5

Create Temporary Tables- Local/Global

Temporary tables are two types:

  •  Local Temporary Tables
  •  Global Temporary Tables

When you create Temporary Tables, 
They are created in -->System Databases -->tempdb database --> Temporary Tables .

Local Temporary Tables:

They are visible only to their creators during the same connection to an instance of SQL Server as when the tables were first created or referenced. Local temporary tables are deleted after the user disconnects from the instance of SQL Server. 

A local temporary table is created using #, like #employee.

Create Table #employee
         ID int,
         Name Varchar(255),
         Salary Money,
         Gender char(1)

select * from #employee;

Global Temporary Tables:

They are visible to any user and any connection after they are created, and are deleted when all users that are referencing the table disconnect from the instance of SQL Server.

Global temporary table is created using ##, like ##employee.

Create Table ##employee
         ID int,
         Name Varchar(255),
         Salary Money,
         Gender char(1)

select * from ##employee;