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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article I will describe the Backup & Restore 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.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor ( Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

717 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