Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Creating temporary table
Message
 
 
À
04/02/2014 14:03:50
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01593184
Message ID:
01593192
Vues:
39
This message has been marked as a message which has helped to the initial question of the thread.
>>
>>IF OBJECT_ID('TempDB..#Temp', N'U') IS NOT NULL DROP TABLE #Temp;
>>
>>select numero into #Temp from dbo.Country where Country.Numero < 10;
>>
>>The first check with object_id will verify if the table already exists or not and will drop it if it exists.
>
>Thanks, as I understand this is window query session related. Is that correct?
>
>When doing this, is there some kind of changes that is applied to the database itself or this is memory only?

The temporary table is created in the TempDB database under unique name for the session. So, you can create temporary table with the same name in two different sessions. This is for local #temp tables. If we're talking about global temp table ##temp then this table is shared by all sessions created after the session that created that global table.

You may want to check this interesting article by Peter Larsson

http://sqlblog.com/blogs/peter_larsson/archive/2009/10/15/performance-consideration-when-using-a-table-variable.aspx

-----------------------------
BTW, quite recently we published a new Transact-SQL eBook (the second item in the News right now). Anyone interested in many good Transact-SQL articles on different topics may want to download this PDF file.

Right now we're working on another free eBook for SQL Server DB Engine. This may be even more interesting to get into bottom of many complex problems in SQL Server Database.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform