There are two different ways one can rename view in SQL Server. Let us see in today’s blog post how to rename view. 1) SSMS 2) T-SQL
Method 1 – SSMS
This is the easiest and most people do use this method. First, go to Object Explorer, expand the databases node and further expand your preferred database. Next, select the section Views and right-click on the view which you want to rename.
Once you write click on the view, now you select the option rename. In the next step, you can enter the name of the view and it will be done!
Method 2 – TSQL
This is another method but it is not my preferred method.
EXEC sp_rename @objname = 'schema.oldviewname', @newname = 'newviewname';
That’s it. Once you run the script it will rename the old view. You may see the warning after you run the script above. You will have to replace now the old name with a new name in your queries and stored procedure.
I personally do not like this method. If you have to use this method, I suggest you just drop the older view and recreate the new view. I have found that to be more error-free and if there are any dependencies, I usually come to know early.
If you liked this blog, please do not forget to subscribe to my YouTube Channel – SQL in Sixty Seconds.
Here are my few recent videos and I would like to know what is your feedback about them.
- Queries Using Specific Index – SQL in Sixty Seconds #180
- Read Only Tables – Is it Possible? – SQL in Sixty Seconds #179
- One Scan for 3 Count Sum – SQL in Sixty Seconds #178
- SUM(1) vs COUNT(1) Performance Battle – SQL in Sixty Seconds #177
- COUNT(*) and COUNT(1): Performance Battle – SQL in Sixty Seconds #176
Reference: Pinal Dave (http://blog.SQLAuthority.com)