question

satheesh kumar avatar image
satheesh kumar asked

How find the old name of the user defined procedure?

How find the old name of the user defined procedure?
I unfortunately renamed the procedure but i do not know the old name of it. it has be used by our client. so i am in need of rename it as old. Please help me

Eg:
1.) proc xxxxx
2.) sp_rename 'xxxxx', 'new_name'
3.) i do not know the old name of the userdefined Stored Procedure.
4.) i need to rename the SP to old_name?

With advanced thanks

sql-server-2005
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Scot Hauder avatar image
Scot Hauder answered

Get it from your backups or db schema deploy scripts

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

CirqueDeSQLeil avatar image CirqueDeSQLeil commented ·
Straight and to the point. +1
0 Likes 0 ·
Jeff Moden avatar image Jeff Moden commented ·
I agree. You just can't beat being in control of your own destiny after you've made a mistake. +1
0 Likes 0 ·
Tom Staab avatar image
Tom Staab answered

Do you have any source code available (SQL scripts, other stored procedures, application code, etc.) that referenced the old name? If not, perhaps your client does. In addition, you might be able to find the name if an "object not found" error was logged.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Fatherjack avatar image
Fatherjack answered

If you have the actual script of the query then you could search the system tables to find that text. Use something like:

SELECT OBJECT_NAME(id) , *
FROM syscomments 
WHERE [text] LIKE '%foobar%' 
AND OBJECTPROPERTY(id, 'IsProcedure') = 1 
GROUP BY OBJECT_NAME(id)

where foobar is replaced by some of the code in your procedure


[Edit]
This is actually better for your needs, simply replace foobar with the existing (new) name of the procedure:

SELECT [text]
FROM syscomments 
WHERE OBJECT_NAME(id) = 'foobar'
AND OBJECTPROPERTY(id, 'IsProcedure') = 1 

The [Text] column will show you the original name of the procedure when it was created.

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Matt Whitfield avatar image Matt Whitfield ♦♦ commented ·
+1 for knowing that the system tables hold old names after an sp_rename
0 Likes 0 ·
Fatherjack avatar image Fatherjack ♦♦ commented ·
@Matt, thanks but sadly, I didnt KNOW it but I wondered and went to check!
0 Likes 0 ·
Jeff Moden avatar image Jeff Moden commented ·
Then +1 for your intellectual curiosity! ;-)
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.