Basically, I set up a simple batch script I called dbCreate.bat and put the following commands in it:
sqlcmd -E -dMyDatabaseName -iDBCreateAll.sql
pause
The -E argument tells the script to use your local machine's permissions. You'll need to change this for operations on a remote host. I'll provide a reference page in the links at the end of this article. The "-d" option allows you to specify the database context you want to work with. It's like including the "USE
The last part to running a list of scripts from one master sql file is the contents of the master sql file itself.
--DBCreateAll.sql
:On Error Exit
PRINT 'CREATING DATABASE...'
:r .\DBCreate.sql
PRINT 'FINISHED CREATING DATABASE...'
PRINT 'LOADING DATA...'
:r .\DBDataLoad.sql
PRINT 'FINISHED LOADING DATA...'
PRINT 'FINISHED SETTING UP DATABASE'
It's pretty self explanatory, but basically your batch file calls the immediately following filename. The sqlcmd utility interprets the :r as an instruction to add the text from the referenced sql file to the statement cache for execution.
So that about covers it! Now you have a method to separate your scripts and still run them all in Sql Server.
Reference
No comments:
Post a Comment