SQL SERVER – Rename View

When I rename view objects, I inspect references and retained definitions first. SSMS and sp_rename both need dependency planning.

Old and new drawer fronts are compared beside preserved vessels and supporting fittings.

Historical SSMS Views context menu showing Rename.
Historical SSMS Views context menu showing Rename.
-- Historical rename syntax, after dependency and permission review:
-- EXEC sys.sp_rename @objname=N'dbo.OldViewName',@newname=N'NewViewName',@objtype=N'OBJECT';
SELECT s.name AS SchemaName,v.name AS ViewName,m.definition
FROM sys.views v JOIN sys.schemas s ON s.schema_id=v.schema_id
LEFT JOIN sys.sql_modules m ON m.object_id=v.object_id ORDER BY s.name,v.name;

In SSMS, inspect Rename under the intended database Views folder. Graphical execution does not remove dependency concerns. It is not inherently safer than the T-SQL operation.

  1. In Object Explorer, expand the intended database and its Views folder.
  2. Right-click the specific view and choose Rename after reviewing its dependencies.
  3. Enter the approved new name, then update affected references and validate the application.

Microsoft discourages sp_rename for procedures, functions, views and triggers because module definitions retain the old name. References are not rewritten. Dropping and recreating can lose grants, indexes and metadata. It can also affect availability.

Preserve the definition and required metadata while planning dependencies, grants and application validation. Handle schema-bound dependencies specifically. The read-only inventory can return NULL for unavailable or encrypted definitions.

Reference: Module rename limitations.

Related reading

A view rename is not an automatic dependency rewrite, it is an object-name change with metadata consequences.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

SQL Scripts, SQL Server, SQL View
Previous Post
MySQL Performance – Five Configuration Topics with Version Limits
Next Post
Free Space in Database Files: Check Data and Log Files

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.