Results 1 to 6 of 6

Thread: Importing Stored Procedures from saved SQL (.sql) files.

  1. #1
    Join Date
    Sep 2005
    Location
    Wilmington, NC
    Posts
    3

    Importing Stored Procedures from saved SQL (.sql) files.

    I frequently use the "Generate Script" wizard to create a folder of .sql files (scripts) that I use to then transfer to my colleagues.

    The question is, I don't see how to reverse the procedure, that is, to import the files with a bulk procedure, rather than copying them one at a time. What's the best way to do this?

    thanks

  2. #2
    Join Date
    Dec 2004
    Posts
    502
    When you create the script, you can choose to write multiple objects into a single script instead of separate scripts. Or, you can use the "type" command from the command line to combine text files into one:

    type c:\*.sql > combinedfile.txt

  3. #3
    Join Date
    Sep 2005
    Location
    Wilmington, NC
    Posts
    3

    Missed the point (I think)

    I know I have the option of creating a single file. How does that help with importing all the scripts?

    thanks

  4. #4
    Join Date
    Dec 2004
    Posts
    502
    I assume that when you say you want to "import the files", you want to be able to recreate the objects that were scripted (tables, stored procedures, functions, etc.). Simplest way to recreate them is to copy the script into a Query Analyzer window and execute the script. If all your scripts are combined, you can recreate them all together in one shot.

    If you want a more automated way to recreate the objects, you can use the "osql" command from the command line:

    osql -Uuserid -Ppassword -Sservername -ddatabasename < c:\YourScriptName.sql

    If you don't specify a database, the objects in the script will be created in the master database by default.
    Last edited by nosepicker; 09-19-2005 at 11:22 PM.

  5. #5
    Join Date
    Jul 2005
    Posts
    18
    online6 it sounds like you're not getting the CREATE commands in your scripts.

    When generating scripts, check the formatting tab and that the 'Generate the CREATE command for each object' is checked. This is the default behaviour but might be your prob.

  6. #6
    Join Date
    Sep 2005
    Location
    Wilmington, NC
    Posts
    3

    Cool RE: Script Importing Creation ..

    Yep ... Did the trick using the Query Analyzer.. Just one more question. I need to put the directive "Use db.." as the first
    line so when I execute it, it uses the correct DB. Anyway I can modify the template when I generate the script to do that?

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •