Uncategorized

Refresh all views in database

If there are views created without SCHEMABINDING then persistent metadata for a view can become outdated because of changes to the underlying objects upon which the view depends. To update the view to the latest metadata it can be recreated…
Uncategorized

Drop all views in database

Transact-SQL DECLARE @Stmt NVARCHAR(MAX) SET @Stmt = '' SELECT @Stmt = @Stmt + 'DROP VIEW [' + s.name + '].[' + v.name + '];' FROM sys.views v INNER JOIN sys.schemas s ON s.schema_id = v.schema_id EXECUTE (@Stmt) GO SELECT * FROM sys.views GO 12345678910111213 DECLARE @Stmt NVARCHAR(MAX) SET @Stmt = '' SELECT  @Stmt = @Stmt + 'DROP VIEW [' + s.name + '].[' + v.name + '];' FROM sys.views v INNER JOIN sys.schemas s ON s.schema_id = v.schema_id EXECUTE (@Stmt)GO SELECT * FROM sys.viewsGO