How to edit multiple SQL Stored Procedures ?

  • I have two questions:

     

    1) Is it possible to rename a SQL table –or- copy the content of a table into a new table ?

     

    2) How to replace the renamed or replaced table name inside the code of ALL Stored Procedures that references it ?

  • 1) you can rename a table with sp_rename: http://msdn2.microsoft.com/en-us/library/ms188351.aspx

    2) one way to do this would be to script out all the procs/views/functions and do a search/replace.  I wrote a console app to script out all the objects a while ago for getting a db under source control, it might help you in this: http://www.elsasoft.org/tools.htm.

    HTH 

    ---------------------------------------
    elsasoft.org

  • There are some tools that offer a solution to this problem too. You can try Red-Gate's SQL Refactor which will rename an object and all it's references. Another one is the Visual Studio Team Edition for Database Professionals from Microsoft. This too will rename all references to an object when you run the Rename refactor.

    Other than that, you will need to export all the create scripts to a single file & do a search & replace there as described above.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thank you very much, jezemine and Grant.

Viewing 4 posts - 1 through 3 (of 3 total)

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