What are difference between Local temp table and Global temporary table in SQL Server?

Local Temp Table:

Local temp table is created using the # sign and table name.

Temp table is created for single user session or duration of sql connection of sql and once the session or connection is closed temp table is dropped.

If we are creating the local temp table using the stored procedure then it will be automatically dropped after execution of the sql procedure.

CREATE TABLE #LocalTemp_Test

(

 UID int,

 UName varchar(50),

 UAddress varchar(150),

 UCity varchar(100)

    )

GO

 

Global Temp Table:

Global temp table is created using the ## sign and table name.

Global temp table is created for all user session of sql server and once all the users’ session is closed in sql server global table is automatically droped.

Global table is visible to all users and its dropped one last connection is closed in sql server.

     CREATE TABLE ##GlobalTemp_Test

(

 UID int,

 UName varchar(50),

 UAddress varchar(150),

 UCity varchar(100)

)

GO

Leave a Reply

Your email address will not be published. Required fields are marked *

7 + 3 =


All Rights Reserved 2019 | DesignzRush (OPC) Pvt. Ltd.
Inline
Inline