Calling a script within a script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Normann
    New Member
    • Jan 2007
    • 17

    Calling a script within a script

    Ok I have been searching for days now, so I hope there is someone here who can help me.

    Is there anyway to call a sql script from within a sql script under MS SQL-Server 2005, i.e. a master install script calls a number of smaller scripts to fill out the tables.
  • bplacker
    New Member
    • Sep 2006
    • 121

    #2
    have you tried just inserting the code to call the script where you want it to be called? If so, what happened when you did?

    Comment

    • almaz
      Recognized Expert New Member
      • Dec 2006
      • 168

      #3
      See EXEC and sp_executesql.

      Comment

      • Normann
        New Member
        • Jan 2007
        • 17

        #4
        I am not sure that is what I need. What I am hoping to accomplish is:

        Opening the master install script (D:\DBSCRIPTS\S toreAddIn\maste rinstall.sql)in Server Management Studio, and when executing this script it also runs the other scripts as well. The Scripts are all in different physical files i.e.
        D:\DBSCRIPTS\St oreAddIn\AddCha nge.sql
        D:\DBSCRIPTS\St oreAddIn\AddNew Items.sql
        etc.

        Normally I would just add them into one script and run that, but we have about 25 scripts to run every other day, and if I add all of them together it fast becomes difficult to keep things separated.

        From what I have been able to read about the two functions you mentioned, it is not what I need.

        Normann
        A frustrated SysAdmin

        Comment

        • almaz
          Recognized Expert New Member
          • Dec 2006
          • 168

          #5
          Than you can use SQLCMD mode in Server Management Studio and following syntax:
          Code:
          use MyDatabase
          go
          :r D:\DBSCRIPTS\StoreAddIn\AddChange.sql
          go
          :r D:\DBSCRIPTS\StoreAddIn\AddNewItems.sql

          Comment

          • Normann
            New Member
            • Jan 2007
            • 17

            #6
            Thank you for your help, it works now. That will save me a lot of work and time.

            Normann
            A slightly less frustrated SysAdmin

            Comment

            Working...