Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Anyway to execute multple *.sql files in batch

Author  Topic 

SamC
White Water Yakist

3467 Posts

Posted - 2004-12-24 : 13:32:24
Anyone have a way to chain together multiple *.sql files so they'll execute in sequence?

Sam

nr
SQLTeam MVY

12543 Posts

Posted - 2004-12-24 : 15:48:44
Well you can just have multiple osql commands

type c:\mydir\*.sql > c\myscript.txt
will concatenate them but I prefer a bat file to produce it

set fname=
set fpath=

set fdest=script.sql

echo use mydb >> "%fdest%"
echo go >> "%fdest%"
echo. >> "%fdest%"

echo print 'Tables' >> "%fdest%"
set fpath=Tables
CALL :concat "%fpath%" "%fdest%" file1.sql
CALL :concat "%fpath%" "%fdest%" file2.sql

echo print 'Views' >> "%fdest%"
set fpath=Views
CALL :concat "%fpath%" "%fdest%" file3.sql
CALL :concat "%fpath%" "%fdest%" file4.sql


goto :end

:concat
echo. >> %2
echo print 'processing file - %3 ' >> %2
type %1%3 >> %2

:end




==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2004-12-24 : 19:49:58
Thanks Nigel and Happy Holidays... !!!

Go to Top of Page
   

- Advertisement -