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 «««23456»»»

Creating Tables Expand / Collapse
Author
Message
Posted Monday, February 11, 2013 8:22 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, March 11, 2014 8:44 AM
Points: 212, Visits: 217
I really wasn't sure if I have to 'GO' or not to 'GO' for my answer...I GOed and got it right..So what I learned from this Qotd is whenever there is a doubt just keep GOing









___________________________________________________________________
If I can answer a question then anyone can answer it..trying to reverse the logic..
Post #1418471
Posted Monday, February 11, 2013 8:37 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, April 18, 2014 9:10 AM
Points: 1,192, Visits: 2,024
(Bob Brown) (2/11/2013)
Sean Lange (2/11/2013)
Here is the original code with the GOs commented out so it will be a single batch.


But the GOs are there.


Even if you ignore the erroneous use of the word 'batch' in the question and leave the GOs in place... the third answer is still not correct because it says that only statements 1 and 3 will run successfully, which is not the case.

It's unfortunate because the wording issues are confusing and distract from the intent of the question.
Post #1418478
Posted Monday, February 11, 2013 8:44 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Wednesday, April 09, 2014 10:34 AM
Points: 701, Visits: 1,140
sestell1 (2/11/2013)

Even if you ignore the erroneous use of the word 'batch' in the question and leave the GOs in place... the third answer is still not correct because it says that only statements 1 and 3 will run successfully, which is not the case.

It's unfortunate because the wording issues are confusing and distract from the intent of the question.


I agree! A truce?
Post #1418487
Posted Monday, February 11, 2013 8:50 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, February 04, 2014 7:49 AM
Points: 275, Visits: 227
I saw that the the CREATE TABLE and INSERT INTO #Table would conflict therfore running it as one batch (as stated in the Question) would error the whole statement regardless of the GO commands being there or not being there.

The results are the same if you run the whole query as one batch with or without the 'GO' commands.

Therfore the Answer

Only the 1st and 3rd statement will succeed but no rows will be returned.

is wrong!

And the Correct answer should be.

All statements will fail.

If You run the whole query as 1 Batch (as stated!)

If however, you were asked to run the three independantly in the same Query window then the right answer would be.

Only the 1st and 3rd statement will succeed but no rows will be returned.


Poorly wrote question and needs correcting. (oh and give me the point for a correct answer )


Regards
ld

Stoke-on-Trent
United Kingdom

If at first you don't succeed, go to the pub and drink away your current thought plan.
Post #1418490
Posted Monday, February 11, 2013 10:03 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, March 10, 2014 5:44 PM
Points: 2,225, Visits: 1,258
I have been reading the QODs as of late with a grain of salt. If the wording is correct there is one answer, but given the wording of some of the questions and guessing on the intent the answer is not always as it appears. I guessed at the answer and in doing so I made an assumption.

I assumed that the author was saying "what happens if you include all of the SQL in a batch job or a scheduled script run as a batch job?" THis gives a second meaning to the word batch and made the correct answer correct.

However, I have to agree that GO denotes a batch execution of all previous unexecuted SQL, that is just how it is done. Multiple Go statements are by definition multiple batch executions. If you remove all but the last Go there is a different answer.

But I have to admit that this line of discussion to a rookie, ( and we were all rookies at one time), this discussion is very valuable and educational.

M.


Not all gray hairs are Dinosaurs!
Post #1418537
Posted Monday, February 11, 2013 10:03 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, April 17, 2014 2:32 PM
Points: 535, Visits: 1,630
ldorian81 (2/11/2013)
If you put the whole query into SSMS 2008 and run it without removing the 'GO' commands you will still get the same results as shown below.

Msg 2714, Level 16, State 1, Line 18
There is already an object named '#TempQoD' in the database.

.


That appears on the messages tab. The results tab had the table selected with no rows.
Post #1418538
Posted Monday, February 11, 2013 11:55 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: Wednesday, April 16, 2014 9:46 AM
Points: 3,150, Visits: 1,900
I made the assumption that the author didn't actually understand that GO was a batch separator and was instead focused on the temp table creation process. I hate to make these assumptions but I couldn't see why they would write to run it as one batch when one could not do so without modifying the code supplied. Another flawed QoTD. Thanks for trying.
Post #1418590
Posted Monday, February 11, 2013 12:12 PM
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, March 10, 2014 6:02 PM
Points: 3,764, Visits: 1,051
Wording was confusing, however I managed to get it right.
Saludos,


"El" Jerry.

"A watt of Ottawa" - Gerardo Galvan
Post #1418596
Posted Monday, February 11, 2013 12:51 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, April 17, 2014 2:35 PM
Points: 84, Visits: 320
Since the question didn't ask what version of SQL Server, none of the answers are correct. In SQL 2005, you get an error message, yet you still get one row selected.

Msg 2715, Level 16, State 7, Line 2
Column, parameter, or variable #4: Cannot find data type Date.
Post #1418610
Posted Monday, February 11, 2013 10:12 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, April 09, 2014 2:46 AM
Points: 1,371, Visits: 1,547
I thought the question was straight forward and got that correct. Thanks

~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter

Post #1418746
« Prev Topic | Next Topic »

Add to briefcase «««23456»»»

Permissions Expand / Collapse