Reputation: 3387
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 is grayed out.
Upvotes: 8
Views: 34935
Reputation: 2353
Rename the stored procedure in SQL Server
EXEC sp_rename 'Proc_OldSpName', 'Proc_NewSpName';
Upvotes: 1
Reputation: 15327
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
....
Upvotes: 0
Reputation: 11
Rename stored procedure sql server:
For the correct answer: View this article.
Usage: sp_rename'[old_object_name]','[new_object_name]','[object_type]'
Upvotes: 1
Reputation: 11
sp_rename <oldname> <newname>
In SQL Server 2008 R2, sys.procedures seems to be updated. (in test environment)
Upvotes: 1
Reputation: 273
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.
Upvotes: 10
Reputation: 9709
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.
Upvotes: 12
Reputation: 487
EXEC sp_rename OLDNAME, NEWNAME
This is assuming you can execute SQL statements via VS2008.
Upvotes: 20