更改 SQL Server 2008 中存储过程的名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3169477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 06:45:47  来源:igfitidea点击:

Change name of stored procedure in SQL Server 2008

sqlvisual-studio-2008sql-server-2008

提问by Kimball Robinson

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.

我有一个通过 Visual Studio 2008 编辑的存储过程。有没有一种简单的方法可以更改存储过程的名称?现在,如果我查看 sproc 的属性,sproc 的名称是灰色的。

回答by Derek Flenniken

EXEC sp_rename OLDNAME, NEWNAME

EXEC sp_rename OLDNAME, NEWNAME

This is assuming you can execute SQL statements via VS2008.

这是假设您可以通过 VS2008 执行 SQL 语句。

回答by josephj1989

If you have SSMS, you can right-click on the procedure name and choose rename.

如果您有 SSMS,您可以右键单击程序名称并选择重命名。

The other option is to drop the procedure and recreate it with the new name.

另一种选择是删除该过程并使用新名称重新创建它。

回答by kkk

This question is very old and already seen as answered but just to know that Renaming SP is not a good ideabecause it does not update sys.procedures.

这个问题很老了,已经被视为已回答,但只是要知道重命名 SP 不是一个好主意,因为它不会更新 sys.procedures。

For example, create a SP "sp_abc",

例如,创建一个 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_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.

它仍然包含旧的过程名称 sp_abc。因为当您重命名 SP 时,它不会更新 sys.procedure。

Better solution is to drop the stored procedure and re-create it with the new name.

回答by Manjunath Bilwar

Rename the stored procedure in SQL Server

重命名 SQL Server 中的存储过程

EXEC sp_rename 'Proc_OldSpName', 'Proc_NewSpName';

回答by Greg

sp_rename <oldname> <newname>

In SQL Server 2008 R2, sys.procedures seems to be updated. (in test environment)

在 SQL Server 2008 R2 中,sys.procedures 似乎已更新。(在测试环境中)

回答by Mahesh

Rename stored procedure sql server:

重命名存储过程sql server:

For the correct answer: View this article.

正确答案:查看这篇文章。

Usage: sp_rename'[old_object_name]','[new_object_name]','[object_type]'

用法: sp_rename'[old_object_name]','[new_object_name]','[object_type]'

回答by Basheer AL-MOMANI

as kkkmentioned in his answer

正如kkk他的回答中提到的

Better solutionis to dropthe stored procedure and re-createit with the new name.

Better solutiondrop存储过程,re-create它具有新名称。

to do this

去做这个

DROP PROCEDURE [dbo].[Procedure_Name]

then

然后

Create Procedure [dbo].[GetEmployees]  
as 
....