SQL Server:如何在视图中更改名称?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1402785/
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 03:32:31  来源:igfitidea点击:

SQL Server: How to change name in a view?

sqlsql-serversql-server-2008-express

提问by Fabio Milheiro

I am using Visual Studio 2008 and SQL Server 2008 Express.

我使用的是 Visual Studio 2008 和 SQL Server 2008 Express。

How can I change the name of the view? I can change tables' names, but I can't change the view name.

如何更改视图的名称?我可以更改表的名称,但无法更改视图名称。

Any suggestion?

有什么建议吗?

Thank you, Fabio Milheiro

谢谢你,法比奥·米列罗

回答by MaxiWheat

You can use the ALTER VIEW statement something like this :

您可以像这样使用 ALTER VIEW 语句:

ALTER VIEW dbo.myView
AS
SELECT foo
FROM dbo.bar
WHERE widget = 'foo'
GO

Reference on MSDN

MSDN上的参考

To rename a view, use sp_renameSystem Stored Procedure :

要重命名视图,请使用sp_rename系统存储过程:

EXEC sp_rename 'dbo.myView', 'myNewViewName'

Note: don't include the schema name in the second string, or else you'll get a name like "dbo.dbo.myNewViewName".

注意:不要在第二个字符串中包含模式名称,否则您将获得类似“dbo.dbo.myNewViewName”的名称。

回答by mson

you can use the gui in sms

你可以在短信中使用gui

you can right click view, edit it, then do generate script if you want the code

您可以右键单击视图,编辑它,然后如果需要代码,请生成脚本

回答by Shaun McDonnell

You can use the ALTER command or CREATE a new one and delete the old one.

您可以使用 ALTER 命令或创建一个新命令并删除旧命令。

-Shaun

-肖恩