Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Syntax qustion when creating TEMP table on the fly
Message
De
16/04/2003 23:52:21
 
 
À
16/04/2003 15:53:52
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
00778391
Message ID:
00778704
Vues:
16
>1) the code I want to write is itself part of a large transaction. If have a smaller BEGIN/END TRANS in the code you sent, will that 'mess up' my larger transaction? [I wouldn't think it would, but figured I'd ask]

No, it won't, you can nest transactions. If you already have a transaction, you don't really have to create the inner transaction, but I would still do it to minimize the time you're locking the global table.

>2) if two different users happen to do something in the application such that this code executes at exactly the same time, would it bomb? [since the name of the global temp name is the same]

It shouldn't bomb because when you create a table (permanent or global temporary) inside of a transaction, it is not available to other connections until the transaction is commited. But since we are dropping the table before commiting, it is never available to other connections.

If you want to test this, open two windows in Query Analyzer and paste my code from the previous message to each window. In the first windows, highlight the code up to (and including) the EXEC line, then execute the code. Now the global table exists but it's locked because you haven't commited the transaction yet. Switch to the second window and execute the entire code. You should see that the query hangs, the reason is that the first window keeps the lock on the global table. Now switch back to the first window, highlight the rest of the code and execute it. Now the transaction is commited and you get back the results from the query. Switch to the second window and you'll see the query results there as well. The code in the second window was able to continue as soon as the transaction in the first window was commited. So essentially you had two processes accessing the global table at the same time but only one process could access the table.

Roman
Roman Rehak, MCSD, MCDBA, MCSA
Competitive Computing
354 Mountain View Drive
Colchester, VT 05446-5824
802-764-1729
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform