How to execute sql files in batch

  • Hi ,

    I have some sql files which out of them one will create DB,tables and other will insert data into those tables and other will create proc's ......... like this . Is ther any way to run all these files from a proc to finish my DB creation.

    Thnaks in advance for any solution.

    /********************************************************
    Technology is just a tool,in terms of getting the kids working together and motivating them,the teacher is the most important.
    ********************************************************/

  • copy all the information into one single file and compile in your database.

  • but i want it as a reusable component so that i can run when ever i want

    /********************************************************
    Technology is just a tool,in terms of getting the kids working together and motivating them,the teacher is the most important.
    ********************************************************/

  • Try creating a SP per component

    ie

    usp_CreateDB

    usp_CreateSchema

    usp_GenerateData

    etc etc

    Then within one file exec each of the SPs.

  • But how can i run a script in .sql file in proc, becuase i want it in sql file only (for me no other option)

    /********************************************************
    Technology is just a tool,in terms of getting the kids working together and motivating them,the teacher is the most important.
    ********************************************************/

  • You can use the cmdshell to then run osql that allows you to execute another .sql file

    See Dave's blog

    [/url]

    and

    osql /U sa /P password /d pubs /S SERVERNAME /Q "sp_of_choice" -o output.txt

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply