SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


T-SQL GO statement


T-SQL GO statement

Author
Message
Ken Wymore
Ken Wymore
SSCrazy Eights
SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)

Group: General Forum Members
Points: 9600 Visits: 2469
How often are global temp tables actually used? I recall reading about them when I started using SQL Server but I can't remember ever seeing one used in production. I would guess that ETL processing might be a place to use them?
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)

Group: General Forum Members
Points: 145222 Visits: 13349
Kenneth Wymore (11/23/2010)
How often are global temp tables actually used? I recall reading about them when I started using SQL Server but I can't remember ever seeing one used in production. I would guess that ETL processing might be a place to use them?


I have indeed used them in SSIS. (but actually because a senior someone told me I'd better use global instead of local temp tables in SSIS. But I think there's no real reason to prefer local above global.)


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
bitbucket-25253
bitbucket-25253
SSC-Dedicated
SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)

Group: General Forum Members
Points: 34671 Visits: 25280
Hugo Kornelis (11/23/2010)
bitbucket-25253 (11/23/2010)
Want some more ...
CREATE the temptable as ##
Run the insert code ... do NOT close that instance of SSMS.
Perform the SELECT * FROM ## statement .. right it returns the correct number of rows

Open a second instance of SSMS
Then perform ONLY the SELECT * FROM ## statement in this second instance of SSMS

And yes, you do get the same number of rows returned, Intriguing indeed.

Why intriguing? Table names starting with ## are considered to be global temporary tables. They're available to all sessions, and are only discarded when no sessions use them anymore.


Sorry meant the word "intriguing" as a lame, ok a very lame joke.

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
rVadim
rVadim
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2096 Visits: 2318
My SQL Server 2005 BOL dated April 2006 doesn't mention the [count] argument for the GO command. I guess it was added later, in one of the service packs perhabs.
vk-kirov
vk-kirov
SSCertifiable
SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)

Group: General Forum Members
Points: 5626 Visits: 4408
Kenneth Wymore (11/23/2010)
How often are global temp tables actually used? I recall reading about them when I started using SQL Server but I can't remember ever seeing one used in production.

I've never seen GTTs in production code, too. However, I often use them when I test my T-SQL code.
For example, there is a long-running stored procedure which returns a dataset, and I'm doing an optimized version of that procedure. I want to run a test to ensure that, given specified parameters, both procedures return the same dataset.
I open two SSMS windows, in one of them I run the following script:
CREATE TABLE ##result1 (...);

INSERT ##result1
EXEC dbo.Old_Procedure @param1 = value1, ...


In the other window, I run the following script:
CREATE TABLE ##result2 (...);

INSERT ##result2
EXEC dbo.New_Procedure @param1 = value1, ...


Both procedures execute in parallel, and I can compare the datasets without making junk permanent tables.
Srikanth-348936
Srikanth-348936
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 34
A very nice and tricky question. Thanks to the author of this question. GO with the loop is news to me.
GPO
GPO
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2712 Visits: 1956
You don't even need to use the word 'GO'. You can set the batch separator to be some string other than 'GO' in the SSMS options. Inveterate prankster and SQL guru in his own right, Rob Farley once showed me a really quite awful but just as funny practical joke you can play on your colleague who is in the habit of leaving his or her workstation without locking the screen. Apparently, and I'm not in any way advocating this, you'll cause some pretty disconcerting and inexplicable error messages if you change GO to oh let's say... SELECT. Your friend may spend hours trying to find the source of the problem.

:-)

One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important.
Bertrand Russell

Tom Thomson
Tom Thomson
SSC Guru
SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)

Group: General Forum Members
Points: 50505 Visits: 13157
It's a good question, but now that MS have clearly stated that # (on its own) will not be supported as a temporary table name in a future version of SQL server http://msdn.microsoft.com/en-us/library/ms143729.aspx it's perhaps a bad idea to use it in a question which people will be using for learning.

Tom

Ken Wymore
Ken Wymore
SSCrazy Eights
SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)

Group: General Forum Members
Points: 9600 Visits: 2469
GPO (11/24/2010)
You don't even need to use the word 'GO'. You can set the batch separator to be some string other than 'GO' in the SSMS options. Inveterate prankster and SQL guru in his own right, Rob Farley once showed me a really quite awful but just as funny practical joke you can play on your colleague who is in the habit of leaving his or her workstation without locking the screen. Apparently, and I'm not in any way advocating this, you'll cause some pretty disconcerting and inexplicable error messages if you change GO to oh let's say... SELECT. Your friend may spend hours trying to find the source of the problem.


Well now that's just terrible! Funny, but terrible. I hope no one I work with reads this and gets any ideas!
Ken Wymore
Ken Wymore
SSCrazy Eights
SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)

Group: General Forum Members
Points: 9600 Visits: 2469
Tom.Thomson (11/24/2010)
It's a good question, but now that MS have clearly stated that # (on its own) will not be supported as a temporary table name in a future version of SQL server http://msdn.microsoft.com/en-us/library/ms143729.aspx it's perhaps a bad idea to use it in a question which people will be using for learning.


Good to know Tom. I wouldn't use a table name with just # anyway as I think it is a bad habit and could be confusing. I'm glad Microsoft is eliminating this from being a future issue.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search