Search code examples
sqlt-sqltransactionssybasesap-ase

BEGIN and END in Sybase SQL


I am trying to unite a number of operations into one block in Sybase SQL, in the following way:

BEGIN TRANSACTION MyInsert;
INSERT INTO dbo.Agencies (code, name) VALUES ( 1, 'My Group');
INSERT INTO dbo.Agencies (code, name) VALUES ( 2, 'Their Group');
COMMIT TRANSACTION MyInsert;

When the INSERT statements execute by themselves, they execute just fine and the rows are inserted. When I execute the block, I get the error

Incorrect syntax near the keyword 'BEGIN'.

I tried marking the block with BEGIN and END instead, like so:

BEGIN;
INSERT INTO dbo.Agencies (code, name) VALUES ( 1, 'My Group');
INSERT INTO dbo.Agencies (code, name) VALUES ( 2, 'Their Group');
END;

and I am still getting the same error. How would this work in Sybase SQL?

Thank you very much.


Solution

  • As per my comment: Remove the semicolons - Sybase doesn't like them