run sql files through batch file

Posted on 2013-01-01
Last Modified: 2013-01-01
i need to run few sql files that hv stored procudures in them through a batch files , i dont know anything much abt how to do that , plz help with an example
Question by:panasonic2012
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 39

Expert Comment

by:Pratima Pharande
ID: 38735713
sqlcmd -E -S yoursqlinstance -i backup.sql
refer for more details
LVL 39

Accepted Solution

Pratima Pharande earned 500 total points
ID: 38735714
1) First Open one new notepad

write the sql commands that you want to excute

like this for example


now save the file with .sql suppose say (example.sql)

2) now open another notepad in the same folder

write the following code

osql -S servername -U username -P password <example.sql

save this as .bat extension (this will create the batch file) file

3) double click on the batch file it will excute the commands


Author Comment

ID: 38735762
ok i ran it and it works fine , now i need is to run the batch file to another pc on the network so the sql execution occurs on tht pc , how do i achieve this ?? plz help

Featured Post

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question