Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««12345»»

T-SQL GO statement Expand / Collapse
Author
Message
Posted Tuesday, November 23, 2010 9:58 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Monday, October 20, 2014 11:29 AM
Points: 3,354, Visits: 2,001
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?
Post #1025284
Posted Tuesday, November 23, 2010 11:10 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 11:42 AM
Points: 13,295, Visits: 11,086
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?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1025349
Posted Tuesday, November 23, 2010 11:33 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 10:58 AM
Points: 5,333, Visits: 25,272
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
Post #1025376
Posted Tuesday, November 23, 2010 3:03 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, September 12, 2014 2:16 PM
Points: 990, Visits: 2,223
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.
Post #1025523
Posted Wednesday, November 24, 2010 2:03 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Friday, May 9, 2014 12:47 AM
Points: 3,448, Visits: 4,407
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.
Post #1025719
Posted Wednesday, November 24, 2010 3:39 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, July 9, 2014 11:52 AM
Points: 1, Visits: 33
A very nice and tricky question. Thanks to the author of this question. GO with the loop is news to me.
Post #1025759
Posted Wednesday, November 24, 2010 3:41 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Saturday, October 11, 2014 8:18 PM
Points: 831, Visits: 1,588
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
Post #1025761
Posted Wednesday, November 24, 2010 5:20 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 9:57 AM
Points: 7,801, Visits: 9,551
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
Post #1025805
Posted Wednesday, November 24, 2010 7:32 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Monday, October 20, 2014 11:29 AM
Points: 3,354, Visits: 2,001
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!
Post #1025914
Posted Wednesday, November 24, 2010 7:34 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Monday, October 20, 2014 11:29 AM
Points: 3,354, Visits: 2,001
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.
Post #1025917
« Prev Topic | Next Topic »

Add to briefcase «««12345»»

Permissions Expand / Collapse