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

what is the out put of below queries? a. select * from Emp where null = null; b. select * from Emp where 1=1;

13 Answers   Patni,


What is Trigger?

3 Answers   Misys,


How to change location of errorlog in SQL?

2 Answers   ABC, IBM,


Where do you think the users names and passwords will be stored in sql server?

4 Answers  


I am having table Title with TITLE id,Author ID, Publiser ID , table AUTHOR with Author ID, Author Name, table PUBLISER with Pub ID, Pub name Here hot to find out the publiser id who have relesed the books of patriticular author?

3 Answers  






Hello all, I have data like :- year amt 2004 10 2005 20 2006 30 Now i want output as:- 2004 2005 2006 10 30 60 but i have to use here group by on year.So, i need a single query within that i can find.

3 Answers  


What is a view?

6 Answers  


what purpose does OPENXML clause have in sql server stored procedure?

1 Answers  


on line cluster can we make if yes tell me the procedure

0 Answers   Microsoft,


what is sql injection in sql server?

2 Answers   TATA,


How to know the NAME of the Database and SIZE of the Database at the client node in Sql Server 2005

1 Answers  


Insert syudents details in table.Current system date &time insert into joining time.How do insert?( in sysdate only return current system date how do add time?)

0 Answers  






Categories