MySQL multi CREATE TABLE syntax helper?
I am trying to write a MySQL script that creates multiple tables. I have:
CREATE TABLE `DataBase1`.`tbl_this`(
...
);
CREATE TABLE `DataBase1`.`tbl_that`(
...
);
... (14 more) ...
BUT, only the first statement is executed CREATE TABLE
. I am getting no syntax errors. Erm, is the MSSQL equivalent missing GO
? What am I doing wrong here? how can I get this child to run all tables?
a source to share
How do you execute this script?
If you are trying to run it programmatically, you should be aware that the MySQL API only executes one statement at a time by default. You cannot group them together with a semicolon and expect it to run all instructions.
You can execute each statement CREATE TABLE
individually in a loop, otherwise you can run the script by supplying it as input to the command line client mysql
.
It is not as easy as it would seem to write a general purpose script runner class in your application, because the full script syntax includes many corner cases.
See the answer for loading .sql files from PHP for examples of corner cases .
a source to share