What is the equivalent of 'go' in MySQL?

2019-01-22 20:07发布

问题:

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?

回答1:

Semicolon at the end of the line.

INSERT INTO myTable (ID) values (5);


回答2:

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.



回答3:

Just a simple ;

so try

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


回答4:

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();



回答5:

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



标签: sql mysql tsql