Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Go statements usability

Author  Topic 

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2011-02-05 : 18:51:45
So go statements will run back of code.
My concerns, thoughts.
What i'm afraid of is if some GO statement backfire then the others will execute and binding this with a use of transactions you may have a problem.
I think, go's must be handled with caution and no task interacts with the next one.Unless transactions can surround all the go's(I'm not aware of that.) or use triggers but it gets complex.
Am i wrong, right, in the middle?
Thanks.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-02-05 : 19:02:41
GO is just a batch terminator in Management Studio or similar. You don't use them inside stored procedure or in any application code. They help you create objects such as functions that have to be inside their own batch.

Show us a code example of what problem you think you'd run into with GO.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-02-05 : 19:05:49
I am not sure what you are referring to. I too would need an example, since you asked me to take a look here....



Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2011-02-05 : 21:24:56
Ok i guess it's my mistake.
I'm accustomed to see GO on the begging of sp's like

USE [test4]
GO
/****** Object: StoredProcedure [dbo].[sp_selectan] Script Date: 02/05/2011 16:19:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



So i assumed it can go deeper in the sp to separate p.e. one insert from the next one.
I guess i was wrong.
Go to Top of Page

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2011-02-05 : 21:25:57
Sorry again can you post a function example with go?
What would be the usability in there?
Thanks.
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-02-05 : 21:42:12
That isn't a procedure.

GO is a batch separator

The property sets above the procedure are not directly part of the procedure itself. The functionality of the GO statement is to separate a batch of commands.


Try this to see "why" the functionality , as you put it, is required:


USE master

Create View [test]
as Select Top 1 from sysobjects

Select * FROM test

Drop view test



After you see what happens, stick a "GO" statement between those four commands and you will see the use demonstrated.

You would NOT see the GO statement inside an actual stored procedure, because it is effectively a hard stop, and commit for the statements above it in a T-SQL batch.




Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2011-02-05 : 22:09:32
Thanks.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-02-07 : 05:02:10
Another use of GO Statement
http://beyondrelational.com/blogs/madhivanan/archive/2008/08/06/another-use-of-go-command-in-sql-server-2005.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -