What is a SQL Server Temporary Table?



What is a SQL Server Temporary Table?..

Answer / mohammadali.info

Temporary tables are a useful tool in SQL Server provided to allow for short term use of data. There are two types of temporary table in SQL Server, local and global.

Local temporary tables are only available to the current connection to the database for the current user and are dropped when the connection is closed. Global temporary tables are available to any connection once created, and are dropped when the last connection using it is closed.

Both types of temporary tables are created in the system database tempdb.

Temporary tables can be created like any table in SQL Server with a CREATE TABLE or SELECT..INTO statement. To make the table a local temporary table, you simply prefix the name with a (#). To make the table a global temporary table, prefix it with (##).

-- Create a local temporary table using CREATE TABLE
CREATE TABLE #myTempTable
(
DummyField1 INT,
DummyField2 VARCHAR(20)
)

-- Create a local temporary table using SELECT..INTO
SELECT
age AS DummyField1,
lastname AS DummyField2
INTO #myTempTable
FROM DummyTable

To make these into global temporary tables, just replace (#) with (##)

Is This Answer Correct ?    15 Yes 2 No

Post New Answer

More SQL Server Interview Questions

How to perfor If the table running time is taking 2hours and table is having 10 rows in it?

1 Answers  


What is difference between count (*) and count 1?

0 Answers  


What are the filtered indexes?

0 Answers  


What are difference between Cluster index and Non-Cluster index?

0 Answers   QuestPond,


What are differences in between sql server 2012 and sql server 2016?

0 Answers  






How we create SQL Server 2005 Reporting Services ? Give me Sample

0 Answers   HCL,


Explain cross join or cartesian product in sql?

0 Answers  


A trigger can reference objects outside the current database? State true or false.

0 Answers  


IF more than one Site is accessing the same Database server and I want to move the DB with Minimum down time? How will you do

0 Answers  


What is transaction server isolation?

0 Answers  


How do I shrink an ldf file?

0 Answers  


What does it mean to be in union?

0 Answers  


Categories