Mysql:如何从其他 sql 脚本文件调用 sql 脚本文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4029240/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:33:42  来源:igfitidea点击:

Mysql: How to call sql script file from other sql script file?

sqlmysqlfilecallsql-scripts

提问by Maddy.Shik

Suppose I have wrote script Table_ABC.sql which creates table ABC. I have created many such scripts for each of required tables. Now i want to write a script that call all of these script files in a sequence so basically I want another script file createTables.sql. Mysql provides option to execute a script file from "mysql" shell application but could find some command like exec c:/myscripts/mytable.sql. Please tell me if there is any command that can be written in sql script itself to call other one in latest mysql versions or alternative for same.

假设我编写了创建表 ABC 的脚本 Table_ABC.sql。我为每个必需的表创建了许多这样的脚本。现在我想编写一个脚本,按顺序调用所有这些脚本文件,所以基本上我想要另一个脚本文件 createTables.sql。Mysql 提供了从“mysql”shell 应用程序执行脚本文件的选项,但可以找到一些命令,如exec c:/myscripts/mytable.sql。请告诉我是否有任何可以用 sql 脚本本身编写的命令来调用最新 mysql 版本中的其他命令或相同的替代方法。

Thanks

谢谢

采纳答案by Pablo Santa Cruz

You can use sourcecommand. So your script will be something like:

您可以使用source命令。所以你的脚本将是这样的:

use your_db;
source script/s1.sql;
source script/s2.sql;
-- so on, so forth