MySQL在脚本中包含一个脚本 [英] MySQL Include a script within script

查看:114
本文介绍了MySQL在脚本中包含一个脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我参与了一个将项目从Oracle迁移到MySQL的项目.在Oracle中,当通过命令行运行批处理时,我能够创建一个引用或包含其他外部SQL脚本文件的SQL脚本.我有一个名为CreateAllTables.sql的脚本,在内部看起来像这样:

I'm involved is a project to migrate a project from Oracle to MySQL. In Oracle I have the ability to create a SQL script that references or inlcudes other external SQL script files when the batch is run via command line. I Have a script called CreateAllTables.sql that looks like this internally:

@tables\Site.sql
@tables\Language.sql
@tables\Country.sql
@tables\Locale.sql
@tables\Tag.sql

我已经知道MySQL命令行源"命令,但是我的目标是通过一个命令行调用来调用一个包含其他脚本的主.sql脚本文件,如下所示:

I'm already aware of the MySQL command line "Source" command, but my goal is to invoke a single main .sql script file that includes other scripts via one single command line call like this:

mysql --user=root --password --database=junkdb -vv < CreateAllTables.sql

所以我的问题是如何使用MySQL?

So my question is how do I do this with MySQL?

推荐答案

source为我工作.

# -- foo.sql
DROP TABLE foo;
source bar.sql

# -- bar.sql
CREATE TABLE bar (i INT NOT NULL);

$ mysql ... < foo.sql

现在表 foo 消失了,并且创建了 bar .

Now table foo is gone and bar is created.

这篇关于MySQL在脚本中包含一个脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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