How do I create a stored procedure that calls sp_refreshview for each view in the database?

Posted by Allrameest on Stack Overflow See other posts from Stack Overflow or by Allrameest
Published on 2010-03-22T10:12:05Z Indexed on 2010/03/22 10:21 UTC
Read the original article Hit count: 272

Today I run this

select 'exec sp_refreshview N''['+table_schema+'].['+table_name+']'''
from information_schema.tables
where table_type = 'view'

This generates a lot of: exec sp_refreshview N'[SCHEMA].[TABLE]'. I then copy the result to the query editor window and run all those execs.

How do I do this all at once? I would like to have a stored procedure called something like dev.RefreshAllViews which I can execute to do this...

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about stored-procedures