Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rebuild view in SQL Server 2008

There is a view in my DB that someone defined with a * from one table. I just added a new column to that table and I want the view to reflect the new column. Besides re-executing the view creation script, is there another way to rebuild the view? I am looking for something similar to how sp_recompile will recompile a stored procedure (or more accurately flag it to be compiled next time it is called).

Update: On a long shot I tried calling sp_recompile on the view and while the call worked, it didn't rebuild the view.

Update 2: I would like to be able to do this from a script. So the script that adds the columns to the table could also update the view. So like I said, something similar to sp_recompile.

like image 543
Jim McKeeth Avatar asked Oct 12 '09 23:10

Jim McKeeth


1 Answers

I believe what you're looking for is

sp_refreshview [ @viewname = ] 'viewname' 

Updates the metadata for the specified non-schema-bound view. Persistent metadata for a view can become outdated because of changes to the underlying objects upon which the view depends.

See Microsoft Docs

like image 194
Cory Avatar answered Oct 10 '22 01:10

Cory