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 modify the underlying query of an existing view?

0 Answers  


What is in place upgrade in sql server?

0 Answers  


What is store procedure? When do you use?

0 Answers  


What is SQL Profiler what is the use of it?

2 Answers   247Customer, Steria,


Explain the properties of sub-query in sql server?

0 Answers  






in tabase table having a column in it empname field is there which having 5 duplicate values is there i want deleted all the duplicates i want showing only one name only.

7 Answers  


Is it possible to allow NULL values in foreign key? I s it possible to use different constraints for the same column in the table (i.e) (id int NOT NULL,UNIQUEUE)

1 Answers  


How to sort query output in descending order in ms sql server?

0 Answers  


What is key set driven?

0 Answers  


what is the disadvantage of SQL Loder?

1 Answers   TCS,


What is hierarchy, what are its types and difference between them? : sql server analysis services, ssas

0 Answers  


Create Index myIndex On myTable(myColumn) What type of Index will get created after executing the above statement

3 Answers  


Categories