Home > front end >  Changing a view's name using sp_rename SQL
Changing a view's name using sp_rename SQL

Time:09-21

I want to change my view's name using T-SQL (not trough SSMS features)

In Microsoft Docs it says that we can use sp_rename to do this, but doesn't explain how exactly to do that

I've tried these two approaches, but neither worked:

exec sp_rename 'dbo.priceMoreThan5', 'priceMoreThan10', 'VIEW

exec sp_rename @objname = 'dbo.priceMoreThan5', @newname= 'priceMoreThan10'

Does anyone know how to do this??

CodePudding user response:

To rename a view or any object in a schema you should use "Schema Name" and "View Name" concatenate with "." You do not have to write schema name but In order to ensure what schema's object which you want to rename will be most secure way. For Example; Schema Name : "dbo" View Name : "FirstView" New View Name : "SecondView"

EXEC sp_rename 'dbo.FirstView', 'SecondView';

And also you can check this link that includes the same question and answers

  • Related