-1

How can I change a view's name using sp_rename? The Microsoft Docs isn't clear enough for me.

I tried these two codes, but neither of them worked:

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

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

Mohammad
  • 98
  • 8
  • 2
    See the [documentation](https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-rename-transact-sql?view=sql-server-ver16); you want `'OBJECT'` not `'VIEW'`. – Thom A Sep 20 '22 at 07:40

1 Answers1

2

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

Ömer A.
  • 66
  • 3