Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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 @ 2:07 AM
Points: 12,903, Visits: 32,145
Comments posted to this topic are about the item sp_rename and the procedure definition

Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1602548
Posted Wednesday, August 13, 2014 12:15 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 4:51 AM
Points: 1,284, Visits: 610
Good question, didn`t touch sp_rename since ages
Thx.
Post #1602576
Posted Wednesday, August 13, 2014 12:38 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 4:45 AM
Points: 13,043, Visits: 10,808
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 LessThanDot.

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


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 7:33 AM
Points: 2,542, Visits: 2,410
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


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: Today @ 3:53 AM
Points: 3,986, Visits: 5,241
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
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: 2 days ago @ 2:27 AM
Points: 751, Visits: 242
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
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Yesterday @ 1:48 PM
Points: 4,053, Visits: 3,490
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
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Yesterday @ 11:12 AM
Points: 579, Visits: 359
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
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Yesterday @ 1:48 PM
Points: 4,053, Visits: 3,490
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: Today @ 4:14 AM
Points: 1,094, Visits: 2,333
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