Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 1234»»»

sp_rename and the procedure definition Expand / Collapse
Author
Message
Posted Tuesday, August 12, 2014 9:28 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 11:52 AM
Points: 14,550, Visits: 38,419
Comments posted to this topic are about the item sp_rename and the procedure definition

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Post #1602548
Posted Wednesday, August 13, 2014 12:15 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, October 25, 2016 7:23 AM
Points: 2,456, Visits: 1,108
Good question, didn`t touch sp_rename since ages
Thx.
Post #1602576
Posted Wednesday, August 13, 2014 12:38 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: 2 days ago @ 2:09 AM
Points: 15,501, Visits: 13,163
Great question, and a fine example of why sp_rename should be avoided.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1602580
Posted Wednesday, August 13, 2014 1:47 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 2:28 AM
Points: 3,369, Visits: 3,191
sp_rename leave unaltered the definition, (see sys.syscomments)
create procedure My_proc
as
select 1 as a
go
SELECT * FROM sys.syscomments
WHERE object_name(id) = 'My_proc'
go
exec sp_rename My_proc,Myproc
SELECT * FROM sys.syscomments
WHERE object_name(id) = 'Myproc'

After the rename the definition in the columnn "text" is unaltered.
The only advantage of sp_rename instead of "drop and re-create" is that you shouldn't reassign permissions on procedure.
Post #1602605
Posted Wednesday, August 13, 2014 3:30 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 6:42 AM
Points: 5,362, Visits: 7,071
sp_rename is usefull for tables and columns, but avoid like the plague for the rest.

nice, question, thanks Lowell


____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
Post #1602626
Posted Wednesday, August 13, 2014 4:51 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, November 3, 2016 9:02 AM
Points: 1,007, Visits: 358
It says it very clearly here: http://msdn.microsoft.com/en-gb/library/ms188351.aspx

"Changes the name of a user-created object in the current database. This object can be a table, index, column, alias data type, or Microsoft .NET Framework common language runtime (CLR) user-defined type."

"Renaming a stored procedure, function, view, or trigger will not change the name of the corresponding object name in the definition column of the sys.sql_modules catalog view. Therefore, we recommend that sp_rename not be used to rename these object types. Instead, drop and re-create the object with its new name.
Renaming an object such as a table or column will not automatically rename references to that object. You must modify any objects that reference the renamed object manually. For example, if you rename a table column and that column is referenced in a trigger, you must modify the trigger to reflect the new column name. Use sys.sql_expression_dependencies to list dependencies on the object before renaming it."
Post #1602646
Posted Wednesday, August 13, 2014 5:13 AM
SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 1:35 PM
Points: 9,955, Visits: 9,356
Nice question. Thanks.


Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Post #1602657
Posted Wednesday, August 13, 2014 6:01 AM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Tuesday, November 29, 2016 6:33 AM
Points: 700, Visits: 468
It's a good question. Learned something today.

Actually, if you run the script as is it will not even rename the object.

Since it is lacking a GO statement between the SELECT and the EXECUTE, the last statement just becomes part of the procedure.

At first, I wondered if that intentionally part of the actual question :)


---------------
Mel.
Post #1602685
Posted Wednesday, August 13, 2014 6:03 AM
SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 1:35 PM
Points: 9,955, Visits: 9,356
SqlMel (8/13/2014)
It's a good question. Learned something today.

Actually, if you run the script as is it will not even rename the object.

Since it is lacking a GO statement between the SELECT and the EXECUTE, the last statement just becomes part of the procedure.

At first, I wondered if that intentionally part of the actual question :)

Yeah, me too. But then I re-read the question and it was pretty clear.



Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Post #1602686
Posted Wednesday, August 13, 2014 6:04 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, April 3, 2015 7:22 AM
Points: 1,244, Visits: 2,754
Yep, good question, learned something today and I answered the question AFTER getting my coffee.
Post #1602688
« Prev Topic | Next Topic »

Add to briefcase 1234»»»

Permissions Expand / Collapse