How to Export Stored Procedures to Text Files?

  • I have over 100 Stored Procedures in my database and would like to know how to export them to text files as a backup? (Not the output data of the Stored Procedure, but the Stored Procedure itself.)

    Please help! Thank you

     

     

  • Nisha - you can use enterprise manager and the scripting wizard to script the text either into individual files or all stored procedures in one big file and then print them out!

    if you right click on the database - go to "all tasks" - generate sql scripts - you can then enter your specs in each tab...under the options tab you can check either the "create one file" or "create one file per object"!

    hth!







    **ASCII stupid question, get a stupid ANSI !!!**

  • Check uot SQLDMO is BOL.

    It has scripting capabilities.

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Check uot SQLDMO is BOL.

    It has scripting capabilities.

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Sushila, Thanks a ton! I hadn't explored the option you mentioned.

    It worked and I've gained more SQL knowledge. Thank U once again

  • anytime!







    **ASCII stupid question, get a stupid ANSI !!!**

  • for an instance you can do it other alternet way too use L:

    sp_helptext 'yrspname'  it will display the text / code of yr sp copy / save it to .txt file .

    HTH

    Regards.

     

    Hemantgiri S. Goswami | SQL Server Specialist & Consultant
    SQL Server Citation[/url] | Follow me on Twitter

  • Following up on the solution provided by Sushila, is there a way to script all stored procedures in the database to seperate files with the same names as the stored procedures?

    This is driving me nuts. The method provided by Sushila can script the SPs to a file one by one or all at once in a single file, but can I do all of them together in seprate files with the same names as original.

  • From within SQL-EM, highlight the list of stored procedures within the database.

    After right click and choosing Tasks-->Generate SQL Scripts, the "Generate SQL Scripts" window appears.

    the [General] tab will show those objects to be scripted

    switch to the [Options] tab. The bottom right corner has an option to script all selected objects as one file or one file per object.

    When you click the OK button it will ask for the folder into which each file will be saved. stored procedures will have a .PRC extension

    -----

    Robert

  • In addition to Robert's post I just wanted to mention that the Help provided with SQL Server (BOL - Books on line) is pretty extensive & comprehensive and that's usually the first place I would look for solutions!:)







    **ASCII stupid question, get a stupid ANSI !!!**

  • rcavill (12/12/2007)


    From within SQL-EM, highlight the list of stored procedures within the database.

    After right click and choosing Tasks-->Generate SQL Scripts, the "Generate SQL Scripts" window appears.

    the [General] tab will show those objects to be scripted

    switch to the [Options] tab. The bottom right corner has an option to script all selected objects as one file or one file per object.

    When you click the OK button it will ask for the folder into which each file will be saved. stored procedures will have a .PRC extension

    -----

    Robert

    Hi Robert,

    Thanks for the quick reply to my post.

    I'm using SQL Server 2005 and in Management Studio, when I right click a SP, I don't get a 'Tasks' option. I only get that when I right-click a database. But with that option, I can't save multiple SPs to multiple files at once.

    Please help.

  • sushila (12/12/2007)


    In addition to Robert's post I just wanted to mention that the Help provided with SQL Server (BOL - Books on line) is pretty extensive & comprehensive and that's usually the first place I would look for solutions!:)

    Hi,

    Could you please guide me to BOL? I'm a newbie here and I'm not sure what or where BOL is.

  • It would appear that the ability to send scripts, one per file, when selecting multiple objects, is not in the Script Wizard of MS SQL Server Management Studio in SQL 2005. Another of those loss of functionality moving to SQL 2005.

    The option I had mentioned is available in the SQL Enterprise Manager for SQL 2000.

    BOL = Books On Line.

    For SQL 2005 navigate to

    Start --> Programs --> Microsoft SQL Server 2005 --> Documentation & Tutorials --> SQL Server Books Online

    or choose Help --> How Do I once in the SQL Server Mangement Studio

  • Thanks rcavill .

    Does anyone know of a way to export Stored procedures from a database to individual files with the same names as the respective SPs?

    Gracias

  • Noman Salim (12/12/2007)


    Thanks rcavill .

    Does anyone know of a way to export Stored procedures from a database to individual files with the same names as the respective SPs?

    Gracias

    Didn't realize you were working with 2005 - you should post this in the 2005 forum as well - definitely the right readership there...

    I haven't started working with 2005 yet - a cursory look indicates that there doesn't seem an easy way (as in 2K) to script to individual files - even the "if exists..drop" and "create object..." seem to be generated with 2 separate scripts that are then supposed to be appended...if I find anything as simple as the 2K one I'll post it.

    Meanwhile, maybe you could open up your db in 2k - create your scripts and then move back to 2005 for everything else....:unsure:







    **ASCII stupid question, get a stupid ANSI !!!**

Viewing 15 posts - 1 through 15 (of 26 total)

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