Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

one sql script executes several scripts

Status
Not open for further replies.

HobbyMan

Programmer
Sep 22, 2000
25
0
0
US
I have worked with Oracle in the past. If I wanted a single
script to run several scripts I could do this (in Oracle):

list of files: main.sql
a.sql
b.sql
c.sql

contents of main.sql would be:
@@a
@@b
@@c

Then all I would have to do is execute "main.sql" which
would in turn execute the other scripts.

Is this possible in sql server? I have looked in
the online manual and can't find what I am looking
for.

lance
 
What you could do is either setup an SP to execute them or design a PAckage that can execute. You could then schedule the package to run a Job at set times. Ashley L Rickards
SQL DBA
 
I guess I did not explain myself very well.

I have my files in the directory:
D:\Coding\Sql

I want a master script to kick-off the real scripts.

What is the syntax, that I need to use, to call the real
scripts from the master script?

example:
contents of main.sql (this is not the REAL syntax, that is what I am asking) :

run D:\Coding\Sql\a.sql
run D:\Coding\Sql\b.sql
run D:\Coding\Sql\c.sql


My reasoning:
I have a script to create my tables and constaints.
I have a script for all of my grants
I have a script to insert data into my "lookup" tables
I wish to keep this sql statements in seperate files.

Lance
 

You can use OSQL (or ISQL) to run the scripts. OSQL is a command line utility so you can run it from a batch file and include as many executes as needed.

Example: Main.bat using SQL Authentication

OSQL -S ServerName -U login -P Password -d db_name -i a.sql
OSQL -S ServerName -U login -P Password -d db_name -i b.sql
OSQL -S ServerName -U login -P Password -d db_name -i c.sql

Example: Main.bat using NT Authentication

OSQL -S ServerName -E -d db_name -i a.sql
OSQL -S ServerName -E -d db_name -i b.sql
OSQL -S ServerName -E -d db_name -i c.sql

NOTE 1: -E option indicates use trusted connection

NOTE 2: See SQL BOL for more options and detailed info Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top