SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Find all Procedures, Views, Functions that have been renamed

By David Hay,

We have had a standard practice of using sp_rename on procedures when moving code for years. This is now causing issues when we want to automate some processes of scripting in/out certain objects.


This will return database, object id, object name, and the first 50 of syscomments where the object name is not found in the 1st block of syscomments. It's ugly and a kludge but it works. Anyone care to expand on it is more than welcome. I need to add a block for triggers as well as they are defined in syscomments to, but we hardly use them, and doubt we would rename one.


With the list, you can then recreate them with the proper names either via scripting, or SSMS enterprise manager. I just drop them, as they are 99.9% obsolete objects.




Quote from BOL:

Renaming a stored procedure, view or trigger will not change the name of the corresponding object name in the syscomments table. This may result in problems generating a script for the object as the old name
will be inserted from the syscomments table into the CREATE statement. For best results, do not rename these object types. Instead, drop and re-create the object by its new name.



Total article views: 783 | Views in the last 30 days: 1
Related Articles

Rename() broken?

After renaming an object (e.g. user defined function), the Script() method will not work as expected...


Scripting Objects Including Permissions

Scripting Objects Including Permissions


renaming tables from script

is it possible to script a rename of all tables and database name?


SSIS script object

Script object Design Script does not open up script editor


Generating Scripts for Database Objects

Creating Seperate Scripts Per Object

stored procedure