Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include SQL file to another SQL file

I have a specific SQL file that may be "connected" to another, more generic SQL init file.

Is it possible to somehow include reference from one SQL file to another SQL file?

I am using Oracle and the DB is populated using Spring DataSourceInitializer class.

like image 795
sergionni Avatar asked Nov 24 '10 16:11

sergionni


People also ask

How do I import SQL File into another SQL File?

Open SQL Server Management Studio. Connect to an instance of the SQL Server Database Engine or localhost. Expand Databases, right-click a database (test in the example below), point to Tasks, and click Import Flat File above Import Data.

HOW include SQL File?

In Object Explorer, connect to an instance of the SQL Server Database Engine and then expand that instance. Expand Databases, right-click the database from which to add the files, and then click Properties. In the Database Properties dialog box, select the Files page. To add a data or transaction log file, click Add.

How do I run a SQL script from another SQL script?

If your scripts are . sql (or any kind of text) file, as @Abe Miesller says (upvoted) you can run them from within SSMS via the :r command, when SQLCMD mode is enabled. You would have to know and script the exact file path and name. This cannot be done from within a stored procedure.


1 Answers

If you are using SQL*Plus to run your script, you can use the @ (or @@) sign to include another SQL script.

See the manual for details:

http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12002.htm#i2696724

http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12003.htm#i2696759

like image 187
a_horse_with_no_name Avatar answered Sep 18 '22 09:09

a_horse_with_no_name