Reputation: 761
In Oracle database, we can link SQL scripts inside other SQL script like this:
@@ drop.sql
Is it possible to do similar in MySQL database?
Basically, I want to automate whole database installation by creating new tables, constraints and basic data. For that, it would be good to maintain different type of SQL statements in different SQL scripts/files.
But to install database, we should run run only one SQL script, which should be pointing other SQL scripts from inside.
Also want to do it without any other programming language. It would be better to do it with SQL script only (like Oracle supports).
Upvotes: 2
Views: 1059
Reputation: 345
Yes, you can, using the command source
(which short form is \.
). Example:
script1.sql
SELECT 'First hello from script1';
source script2.sql;
SELECT 'Second hello from script1';
script2.sql
SELECT 'Hello from script2';
Calling script1.sql:
$ mysql -s < script1.sql
First hello from script1
Hello from script2
Second hello from script1
More info here: http://dev.mysql.com/doc/refman/5.6/en/mysql-commands.html
Upvotes: 2