?
Solved

SQL - How to run sql files automatically

Posted on 2012-09-16
7
Medium Priority
?
306 Views
Last Modified: 2012-09-18
I have been running manually a set of SQL files one after another.
Now I would like to schedule a time to run all these SQL file one after another upon each run successfully.  What do I do to do that?
0
Comment
Question by:tommym121
7 Comments
 
LVL 5

Assisted Solution

by:elevationkevin
elevationkevin earned 400 total points
ID: 38404256
Here is a handful of tips that helped me with kinda the same thing:

1. You can write a bat file to execute them using sqlcmd Utility.

2. Write a shell script or similar to run them sequentially.

3. SQL Deploy tool by SSW Australia. (I got this from the web but haven't tried it.)

4. Pipe the dir /b > foo.txt output to a file
Add sqlcmd at the start of each line etc using a decent text editor like notepad++

5. copy *.sql /a my_big_script.sql
Then run the resulting file as one script (via sqlcmd or Management Studio)

6. Here is a blog post link that might be useful. It's about using Powershell.

http://sqlblogcasts.com/blogs/martinbell/archive/2009/07/30/Executing-all-.SQL-files-in-a-directory-with-Powershell.aspx
0
 
LVL 5

Assisted Solution

by:sameer_goyal
sameer_goyal earned 800 total points
ID: 38404284
You can create a sql job to execute each sql file at different steps. This is the easiest way to automate sql execution.

Let me know if you need help on how to create a sql job
0
 
LVL 6

Assisted Solution

by:Ashok Kumar
Ashok Kumar earned 400 total points
ID: 38404290
SQL job, would be a perfect.

1. Write them as stored procedure, same as you sequence executed manually. also.. space up time between each. As you know the db keeps growing, you will have to space out time for running each query, so there is no over lapping and result set isn't affected.

2. Setup jobs and alert notice to you. Alerts will let you know the sucess & failure,
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 

Author Comment

by:tommym121
ID: 38405171
sameer_goyal
any good tutorial to setup and monitor any error in running sql files.?
0
 
LVL 10

Assisted Solution

by:Ramesh Babu Vavilla
Ramesh Babu Vavilla earned 400 total points
ID: 38405215
0
 
LVL 5

Accepted Solution

by:
sameer_goyal earned 800 total points
ID: 38405337
0
 

Author Closing Comment

by:tommym121
ID: 38412072
Thanks
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview

809 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