Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I use GO command in sybase?

Tags:

sql

tsql

sap-ase

Why should I use GO when writing sql for sybase? In most of the existing sql my project has, there are no GOs but when DDL is generated for table creation, as an example, the application inserts many GO statements.

Thanks to the answers, I understand that GO is similar to ; in other databases, as people have helpfully pointed out it is a Delimiter.

An added question then, is GO in sybase exactly equivalent to typing ; in Oracle?

like image 719
prismaticorb Avatar asked Nov 14 '11 18:11

prismaticorb


2 Answers

It's a batch separator. GO is used to tell the engine to process everything after the word GO as a new command in a batch.

CREATE PROC usp_blah as ...
GO

CREATE some-otherproc as ...
GO

Without GO, the optimizer would throw an error at the second CREATE statement

like image 144
Stuart Ainsworth Avatar answered Sep 20 '22 11:09

Stuart Ainsworth


Compare:

    Do something
    GO
    Do something else
    Go

To:

    Do something
    Do something else

If there is an error during 'Do something' in the first example then 'Do something else' will still run. This is not the case in the second example. And as Stuart pointed out there are some actions that require have to be the first statement of a batch, meaning you have to place GO before them unless the are the first line of your file.

like image 22
Brandon Moore Avatar answered Sep 20 '22 11:09

Brandon Moore