<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Views &#8211; SQLpowered.com</title>
	<atom:link href="https://sqlpowered.com/script-category/views/feed/" rel="self" type="application/rss+xml" />
	<link>https://sqlpowered.com</link>
	<description>SQL Server + BI</description>
	<lastBuildDate>Mon, 14 Oct 2024 09:09:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://sqlpowered.com/wp-content/uploads/2020/07/FavIcon-e1594067873682-99x100.png</url>
	<title>Views &#8211; SQLpowered.com</title>
	<link>https://sqlpowered.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Refresh all views in database</title>
		<link>https://sqlpowered.com/script/refresh-all-views-in-database/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Tue, 07 Jul 2020 09:01:30 +0000</pubDate>
				<guid isPermaLink="false">https://sqlpowered.com/?post_type=script&#038;p=4407</guid>

					<description><![CDATA[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 or refreshed using the sp_refreshview procedure. Because views and its...]]></description>
										<content:encoded><![CDATA[<p>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 or refreshed using the <a href="https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-refreshview-transact-sql?view=sql-server-ver15" rel="noopener noreferrer">sp_refreshview</a> procedure. Because views and its metadata can be nested refresh must be executed for all levels.</p>
<p>The following script will search for all views in the database and perform a call of sp_refreshview for each of them. Please adjust the command execution to your nesting level. Currently, it is set to three levels.</p>
<pre class="lang:tsql decode:true ">DECLARE @Stmt NVARCHAR(MAX)
 
SET @Stmt = ''
 
SELECT  @Stmt = @Stmt + 'EXEC sp_refreshview ''[' + [s].[name] + '].[' + [v].[name] + ']'';' + CHAR(13) 
FROM [sys].[views] [v]
	INNER JOIN [sys].[schemas] [s] ON [s].[schema_id] = [v].[schema_id]
ORDER BY [s].[name], [v].[name]

PRINT @Stmt

-- Copy as needed to cover lowest nested level
EXECUTE (@Stmt)
EXECUTE (@Stmt)
EXECUTE (@Stmt)
GO
 
-- Check modify_date that it's updated
SELECT [s].[name] [SchemaName], [v].[name] [ViewName], [v].[create_date], [v].[modify_date]
FROM [sys].[views] [v]
	INNER JOIN [sys].[schemas] [s] ON [s].[schema_id] = [v].[schema_id]
ORDER BY [s].[name], [v].[name]
GO</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Drop all views in database</title>
		<link>https://sqlpowered.com/script/drop-all-views-in-database/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Mon, 13 Aug 2018 19:40:30 +0000</pubDate>
				<guid isPermaLink="false">https://sqlpowered.com/?post_type=script&#038;p=2716</guid>

					<description><![CDATA[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]]></description>
										<content:encoded><![CDATA[<pre class="lang:tsql decode:true ">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</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
