Solved

run sql files through batch file

Posted on 2013-01-01
3
428 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
  • 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

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now