MSSQL, Tips and TricksSQL Server: Refresh View Metadata

SQL Server: Refresh View Metadata

After making changes to tables, you may need to refresh the metedata of the views pointing to those tables.
To refresh the metadata of all views in the database, use this

USE {database name here}
GO

DECLARE @sqlcmd NVARCHAR(MAX) = ''
SELECT @sqlcmd = @sqlcmd + 'EXEC sp_refreshview ''' + name + ''';'
FROM sys.objects AS so
WHERE so.type = 'V'

SELECT @sqlcmd

-- uncomment to execute
--EXEC(@sqlcmd)

Categories: MSSQL, Tips and Tricks

Comments

No Comments Yet. Be the first?

Post a comment

Your email address will not be published. Required fields are marked *