Answer Posted / 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 View All Answers
What is difference between delete and truncate commands?
Explain tables in SQL Azure?
What is use of except clause? How does it differ from not in clause?
What are the diifferences between the ms sql server vs mysql?
What are examples of triggers?
What is the openxml statement in sql server?
What are the properties of the relational tables?
What is a print index?
How many full-text indexes can a table have?
what exactly sql injuction.how to overcome.....
Where sql server user names and passwords are stored in sql server? : sql server database administration
Tell me what is normalization? Explain different forms of normalization?
Create a dts package to produce a text file using the ‘update statistics’ command for the tables in a database with obsolete statistics.
What is plan freezing?
What is the default server name for sql server?