Hi friends
I want to know what is the difference between local temporary table and a global temporary table in SQL Server ?
Thank you.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Anil KumarPosted Jun 5, 2012, 8:51 AM
Temporary and Global Temporary Table in SQL Server 2008
Jignesh TrivediPosted Jun 5, 2012, 8:50 AM
Local temporary tables 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.
In other word A local temporary table, #table_name, exists only for the duration of a user session or the procedure that created the temporary table.
CREATE TABLE #LocalTempTableTest(
ID int,
Name varchar(50)
)
insert into #LocalTempTableTest values ( 1, 'Jignesh Trivedi');
Local Temp table cannot be shared between multiple users.
Global temporary tables 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.
Temporary tables are similar to permanent tables, except temporary tables are stored in tempdb and are deleted automatically when no longer in use.
CREATE TABLE ##LocalTempTableTestGlobal(
ID int,
Name varchar(50)
)
insert into #LocalTempTableTestGlobal values ( 1, 'Jignesh Trivedi');
Global Temp table can be shared between multiple users.
hope this will help u.