SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to Execute *.sql scripts using SQLCMD in batch file format


How to Execute *.sql scripts using SQLCMD in batch file format

Author
Message
infantpj
infantpj
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 4
Hello All,
I have a few *.sql scripts. Typically a few Create DB Scripts followed by Modify DB Scripts and Then CreateSprocs Scripts. All these scripts need to be run on a daily basis.
Thus I want to Automate the process using a Batch Scripts os that Windows Scheduler can be used to automate at specific Time.
I was trying with SQLCMD, but was not sure of syntax. Can I use SQLCMD or should I use something else?
Thanks,
Jerry
arjun.tewari
arjun.tewari
SSC-Enthusiastic
SSC-Enthusiastic (103 reputation)SSC-Enthusiastic (103 reputation)SSC-Enthusiastic (103 reputation)SSC-Enthusiastic (103 reputation)SSC-Enthusiastic (103 reputation)SSC-Enthusiastic (103 reputation)SSC-Enthusiastic (103 reputation)SSC-Enthusiastic (103 reputation)

Group: General Forum Members
Points: 103 Visits: 186
Hey Jerry,
I would advise to create a proc that will fetch the scripts from the .sql files and schedule it.
Regards,
Arjun
infantpj
infantpj
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 4
Thanks to All,
Here is the solution
>> "D:\ClearviewBuild\OutputofModifyDBandCreateSprocs.txt" Echo Running ModifyBuildQueueDB
"C:\Program Files\Microsoft SQL Server\90\Tools\Binn\SQLCMD.exe" -i "D:\Build\Database\Modify Databases\ModifyCoreDatabase-5-0.sql" >> "D:\Build\OutputofModifyDBandCreateSprocs.txt"
>> "D:\ClearviewBuild\OutputofModifyDBandCreateSprocs.txt" Echo *************************
>> "D:\ClearviewBuild\OutputofModifyDBandCreateSprocs.txt" Echo *************************
>> "D:\ClearviewBuild\OutputofModifyDBandCreateSprocs.txt" Echo Running AcreateAuditSprocs
"C:\Program Files\Microsoft SQL Server\90\Tools\Binn\SQLCMD.exe" -i "D:\Build\Database\Create Sprocs\CreateAuditSprocs.sql" >> "D:\Build\OutputofModifyDBandCreateSprocs.txt"
>> "D:\ClearviewBuild\OutputofModifyDBandCreateSprocs.txt" Echo *************************
>> "D:\ClearviewBuild\OutputofModifyDBandCreateSprocs.txt" Echo *************************


In Brief sqlcmd -i is the command for execting sql scripts and -q is the command line parameter to execte individual SQL Scripts
Added some commenting lines to make the log look neat
Thanks,
Jerry
Erin.
Erin.
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1363 Visits: 558
I am trying to setup a scheduled task using a .cmd file. I want to backup the databases. I have a script, but when the command runs the backups are not generated. I think it is the way I am calling the instance. This is for our Windows Internal database. Here is what I have in the .cmd file.

sqlcmd -S\\.\pipe\mssql$microsoft##ssee\sql\query-E -i"E:\SQL_Backups\scripts\backupDB.sql"
Erin.
Erin.
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1363 Visits: 558
Found my problem. I had a typo. I needed a space before -E.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search