Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 436
  • Last Modified:

run sql files through batch file

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
panasonic2012
Asked:
panasonic2012
  • 2
1 Solution
 
Pratima PharandeCommented:
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
 
Pratima PharandeCommented:
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
 
panasonic2012Author Commented:
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

Technology Partners: 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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now