Hi
How can you define Local Temporary Table and Global Temporary Table in SQL Server ?
How can you Define Local Temporary Table and Global Temporary Table in SQL Server
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Posted Jul 9, 2012, 2:08 AM EDT
For local temp table.
create table #temp1
(your table details)
For global temp table
create table ##temp2
(your table details)
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 9, 2012, 2:31 AM EDT
A temporary table is created and populated on disk, in the system database tempdb — with a session-specific identifier packed onto the name, to differentiate between similarly-named #temp tables created from other sessions. The data in this #temp table (in fact, the table itself) is visible only to the current scope
CREATE TABLE #people
(
PeoPleId INT,
Name VARCHAR(32)
)
Global temporary tables operate much like local temporary tables; they are created in tempdb and cause less locking and logging than permanent tables. However, they are visible to all sessions, until the creating session goes out of scope
CREATE TABLE ##people
(
PeoPleId INT,
Name VARCHAR(32)
)
hope this will help you.
Satyapriya NayakRank #47 · 31.5K reputationPosted Jul 9, 2012, 3:20 AM EDT
Please refer the below links
http://www.codeproject.com/Articles/42553/Quick-Overview-Temporary-Tables-in-SQL-Server-2005
http://www.varindersandhu.in/2011/06/05/sql-server-local-temporary-table-vs-global-temporary-table/
Thanks