Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Batch file Expand / Collapse
Author
Message
Posted Friday, May 29, 2009 7:15 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 3:14 AM
Points: 805, Visits: 1,401
Hi,

I have 20 .sql files to be executed. I am executing one by one in query analyser. But I want to execute all the 20 files as a batch and deliver this batch to client to simplify the process.

How Can I do this?
Post #725776
Posted Friday, May 29, 2009 7:34 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:20 PM
Points: 11,305, Visits: 13,094
You could save all the queries in 1 .sql file separated by the GO statement and then execute the 1 command.

You could create a batch file (.bat) that executes the queries using sqlcmd. Lookup sqlcmd in BOL for syntax.




Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #725794
Posted Friday, May 29, 2009 8:22 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 8:23 AM
Points: 3,315, Visits: 6,723
Or you can add it as a job if it is to be run at a regular interval.


-Roy
Post #725838
Posted Friday, May 29, 2009 8:26 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:20 PM
Points: 11,305, Visits: 13,094
Roy Ernest (5/29/2009)
Or you can add it as a job if it is to be run at a regular interval.


Darn Roy, I was hoping this would have been a suggestion to use PowerShell.




Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #725840
Posted Friday, May 29, 2009 8:29 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 8:23 AM
Points: 3,315, Visits: 6,723
ooops...Sorry.. I have never used powershell so I did not want to make a comment on that. Next time I will know better.

-Roy
Post #725843
Posted Friday, May 29, 2009 8:34 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 2:27 PM
Points: 33,267, Visits: 15,434
I used to deploy changes like this using osql and a batch file. Now I'd use SQLCMD. The SQL Server install runs .sql files for some things using SQLCMD






Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #725845
Posted Friday, May 29, 2009 8:52 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 3:14 AM
Points: 805, Visits: 1,401
Hi

20 files are huge files I cant add them into single .sql

I have to run those 20 as a bath

Thanks
Post #725857
Posted Friday, October 14, 2011 4:58 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, January 4, 2012 4:34 AM
Points: 5, Visits: 61
Create a batch file and save it in the directory where all the sql files are located. To do that follow the below:
1) Open notepad and copy the below:
for %%G in (*.sql) do sqlcmd /S SQLSRV01 /d accounts -E -i"%%G" 
pause

2) Save the file as UAT01.txt
3) Once the file is saved go to the directory where you saved it, and delete .txt and replace it with .bat so it should now read UAT01.bat
Post #1190437
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse