Change name of stored procedure in SQL Server 2008
I have a stored procedure which I edit through Visual Studio 2008. Is there a simple way to change the name of the stored procedure? Right now if I look at the sproc's properties, the name of the sproc i开发者_如何学Pythons grayed out.
EXEC sp_rename OLDNAME, NEWNAME
This is assuming you can execute SQL statements via VS2008.
If you have SSMS, you can right-click on the procedure name and choose rename.
The other option is to drop the procedure and recreate it with the new name.
This question is very old and already seen as answered but just to know that Renaming SP is not a good idea because it does not update sys.procedures.
For example, create a SP "sp_abc",
CREATE PROCEDURE [dbo].[sp_abc]
AS
BEGIN
SET NOCOUNT ON;
SELECT ID,
Name
FROM tbl_Student WHERE IsDeleted = 0
END
Now, Rename it
sp_rename 'sp_abc', 'sp_Newabc'
it shows following warning.
Caution: Changing any part of an object name could break scripts and stored procedures.
Now see sp_Newabc
sp_helptext sp_Newabc
you can see this result.
CREATE PROCEDURE [dbo].[sp_abc]
AS
BEGIN
SET NOCOUNT ON;
SELECT ID,
Name
FROM tbl_Student WHERE IsDeleted = 0
END
It still contains old Procedure name sp_abc. Because when you rename SP it does not update sys.procedure.
Better solution is to drop the stored procedure and re-create it with the new name.
sp_rename <oldname> <newname>
In SQL Server 2008 R2, sys.procedures seems to be updated. (in test environment)
Rename stored procedure sql server:
For the correct answer: View this article.
Usage: sp_rename'[old_object_name]','[new_object_name]','[object_type]'
Rename the stored procedure in SQL Server
EXEC sp_rename 'Proc_OldSpName', 'Proc_NewSpName';
as kkk mentioned in his answer
Better solution
is todrop
the stored procedure andre-create
it with the new name.
to do this
DROP PROCEDURE [dbo].[Procedure_Name]
then
Create Procedure [dbo].[GetEmployees]
as
....
精彩评论