tags:

views:

1295

answers:

6

In TSQL I can state:

insert into myTable (ID) values (5)
GO
select * from myTable

In MySQL I can't write the same query.

What is the correct way to write this query in MySQL?

+11  A: 

Semicolon at the end of the line.

INSERT INTO myTable (ID) values (5);
Jeff Fritz
It doesn' even have to be at the end of line, just at the end of the statement
soulmerge
+6  A: 

Just a simple ;

so try

insert into myTable(ID) values (5);
select * from myTable;
Grant Collins
+2  A: 

Use a semicolon (;). It will separate your statements.

Daniel A. White
+10  A: 

The semicolon is the default delimiter. You can however redefine it to whatever you want with the DELIMITER keyword. From the MySQL manual:

mysql> delimiter //

mysql> CREATE PROCEDURE simpleproc (OUT param1 INT)
    -> BEGIN
    ->   SELECT COUNT(*) INTO param1 FROM t;
    -> END;
    -> //
Query OK, 0 rows affected (0.00 sec)

mysql> delimiter ;

mysql> CALL simpleproc(@a);
Query OK, 0 rows affected (0.00 sec)

This is not limited to stored procedure definitions of course.

Daniel Schneller
A: 

Note that there is nothing magical about the string "GO" in SQLServer isql/osql - it is just the default SQL statement terminator string, and is not a command itself. You can change it to be the semicolon when you start the client using the -c switch:

osql -c ';' other parameters
anon
This is not true, GO is the *batch* terminator. Try:SELECT 1;CREATE PROCEDURE dbo.Test AS SELECT 1versusSELECT 1GOCREATE PROCEDURE dbo.Test AS SELECT 1
Tom H.
A: 

I think the problem is that GO is a batch terminator, not a statement terminator. After explicitly setting transactions, I got this code to execute without telling me that the procedure already exists. Without the transaction statements, I do get an error that the procedure already exists.

start transaction; drop procedure if exists usp_test; commit; start transaction; CREATE PROCEDURE usp_test() SELECT * from books; commit; call usp_test();

Brian