Mysql:如何从其他sql脚本文件调用sql脚本文件? [英] Mysql: How to call sql script file from other sql script file?

查看:393
本文介绍了Mysql:如何从其他sql脚本文件调用sql脚本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

谢谢

推荐答案

您可以使用 source 命令.因此,您的脚本将类似于:

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

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

这篇关于Mysql:如何从其他sql脚本文件调用sql脚本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆