SQL Server Rename View

Learning Objective

The objective of this tutorial to teach you to rename a view in SQL Server Database.

Please note that renaming a view may result in failure for all the objects those are dependent on that view. These objects include triggers, user-defined functions, stored procedures, queries, other views, etc.

So, make sure that after renaming a view you need to update the new view name on these objects. So that the referencing objects are pointing toward the correct view.

 SQL Server rename view using Server Server Management Studio (SSMS)

In order to rename a view in SQL Server using SQL Server Management Studio, you need to perform the following steps.

First, in object explorer, expand the Databases, choose the database name which contains the view that contains the view that you want to rename and expands the Views folder.

Second, right-click on the view that you want to rename.

SQL Server Rename View
SQL Server Rename View

Third, enter the new name for the view and press enter.

SQL Server rename view using Transact-SQL

If you want to rename a view using SQL statement, you can use sp_rename stored procedure.

EXEC sp_rename
@objname = 'dbo.Vwemp',
@newname = 'Vwemp_details';

In this syntax,

@objname – You need to provide the view name using @objname which you want to rename. Note that you must need to provide schema name here along with view name.

@newname – The new name needs to specify here using @newname parameter. Note that you must not specify the schema name here.

Once you execute the sp_rename stored procedure, it returns the following message.

Caution: Changing any part of an object name could break scripts and stored procedures.

In this tutorial, you have learned how to rename a view in SQL Server database using SQL Server Management Studio(SSMS) and Transact-SQL.

Advertisement