Solved

run sql files through batch file

Posted on 2013-01-01
3
433 Views
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
0
Comment
Question by:panasonic2012
[X]
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
3 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 38735713
sqlcmd -E -S yoursqlinstance -i backup.sql
refer for more details
http://stackoverflow.com/questions/3294545/how-to-run-sql-file-from-a-batch-file
0
 
LVL 39

Accepted Solution

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

write the sql commands that you want to excute

like this for example

USE MASTER
go
SELECT * FROM SYSDATABASES
go

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
pause

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

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

refer
http://www.sqlservercentral.com/Forums/Topic501783-8-1.aspx
0
 

Author Comment

by:panasonic2012
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
0

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 (https://www.adremsoft.com/). 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