I have seen people use GO statement between batches of SQL code, but AFAICS it is not mandatory (SQL Server 2008). What are the benefits using GO statements between batches/sets of SQL statements?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They’re not strictly required – they’re just instructions for the SQL Server Management Studio to execute the statements up to this point now and then keep on going.
GOis not a T-SQL keyword or anything – it’s just an instruction that works in SSMS.Sometimes, you need a GO – e.g. if you add a column to a table, and then want to select it again, you need to have a GO between the adding of the column, and the query of it.
E.g. if you try to execute this, you’ll get errors from SSMS:
Results in:
The point is: SSMS is trying to verify the whole statement at once, but on the SELECT statement, it will complain about the missing
DateTimeStampcolumn.If you put a
GObetween the two statements, it’ll work, because SSMS won’t parse and verify the whole statement ahead of time – it will do the first part, and then only parse the second (after theGO).But other than situations like this one, GO is hardly ever required.