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?
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?
Semicolon at the end of the line.
INSERT INTO myTable (ID) values (5);
Just a simple ;
so try
insert into myTable(ID) values (5);
select * from myTable;
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.
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
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();