SQL - How to run sql files automatically

Posted on 2012-09-16
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?
Question by:tommym121
    LVL 5

    Assisted Solution

    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.
    LVL 5

    Assisted Solution

    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
    LVL 6

    Assisted Solution

    by:Ashok Kumar
    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,

    Author Comment

    any good tutorial to setup and monitor any error in running sql files.?
    LVL 10

    Assisted Solution

    LVL 5

    Accepted Solution


    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
    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.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    760 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

    10 Experts available now in Live!

    Get 1:1 Help Now