<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; UNION Not Allowed but OR Allowed in Index View &#8211; Limitation of the View 6</title>
	<atom:link href="http://blog.sqlauthority.com/2010/09/22/sql-server-union-not-allowed-but-or-allowed-in-index-view-limitation-of-the-view-6/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2010/09/22/sql-server-union-not-allowed-but-or-allowed-in-index-view-limitation-of-the-view-6/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Fri, 17 May 2013 15:26:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: SQL SERVER &#8211; Weekly Series &#8211; Memory Lane &#8211; #008 &#171; SQL Server Journey with SQL Authority</title>
		<link>http://blog.sqlauthority.com/2010/09/22/sql-server-union-not-allowed-but-or-allowed-in-index-view-limitation-of-the-view-6/#comment-397398</link>
		<dc:creator><![CDATA[SQL SERVER &#8211; Weekly Series &#8211; Memory Lane &#8211; #008 &#171; SQL Server Journey with SQL Authority]]></dc:creator>
		<pubDate>Sat, 22 Dec 2012 01:32:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=10291#comment-397398</guid>
		<description><![CDATA[[...] UNION Not Allowed but OR Allowed in Index View – Limitation of the View 6 [...]]]></description>
		<content:encoded><![CDATA[<p>[...] UNION Not Allowed but OR Allowed in Index View – Limitation of the View 6 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER &#8211; Indexed Views and Restrictions &#8211; Quiz &#8211; Puzzle &#8211; 7 of 31 &#171; SQL Server Journey with SQL Authority</title>
		<link>http://blog.sqlauthority.com/2010/09/22/sql-server-union-not-allowed-but-or-allowed-in-index-view-limitation-of-the-view-6/#comment-233266</link>
		<dc:creator><![CDATA[SQL SERVER &#8211; Indexed Views and Restrictions &#8211; Quiz &#8211; Puzzle &#8211; 7 of 31 &#171; SQL Server Journey with SQL Authority]]></dc:creator>
		<pubDate>Sun, 08 Jan 2012 01:30:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=10291#comment-233266</guid>
		<description><![CDATA[[...] – Limitation of the View 7  SELF JOIN Not Allowed in Indexed View – Limitation of the View 9  UNION Not Allowed but OR Allowed in Index View – Limitation of the View 6  Keywords View Definition Must Not Contain for Indexed View – Limitation of the View [...]]]></description>
		<content:encoded><![CDATA[<p>[...] – Limitation of the View 7  SELF JOIN Not Allowed in Indexed View – Limitation of the View 9  UNION Not Allowed but OR Allowed in Index View – Limitation of the View 6  Keywords View Definition Must Not Contain for Indexed View – Limitation of the View [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simon Watkins</title>
		<link>http://blog.sqlauthority.com/2010/09/22/sql-server-union-not-allowed-but-or-allowed-in-index-view-limitation-of-the-view-6/#comment-219441</link>
		<dc:creator><![CDATA[Simon Watkins]]></dc:creator>
		<pubDate>Fri, 16 Dec 2011 15:40:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=10291#comment-219441</guid>
		<description><![CDATA[Why could you not use GROUP BY in your indexed view to eliminate duplicates (obviously remembering to include the mandatory COUNT_BIG(*) AS [COUNT]).  Is this a hack?  I want to put it into production code, so if anyone has any reason to expect risk in doing this, then please let me know...

Also worked around the lack of a MAX operation in indexed views by using a Tally Table and COUNT_BIG.  Have since replaced this terrible hack, in my code, with a TOP (1) WITH TIES ... ORDER BY ROW_NUMBER OVER (PARTITION BY ....) operation, as it is not only faster (with the correct indexes), but it doesn&#039;t take the lifetime of an average main sequence star to compute, and it is not a hack.]]></description>
		<content:encoded><![CDATA[<p>Why could you not use GROUP BY in your indexed view to eliminate duplicates (obviously remembering to include the mandatory COUNT_BIG(*) AS [COUNT]).  Is this a hack?  I want to put it into production code, so if anyone has any reason to expect risk in doing this, then please let me know&#8230;</p>
<p>Also worked around the lack of a MAX operation in indexed views by using a Tally Table and COUNT_BIG.  Have since replaced this terrible hack, in my code, with a TOP (1) WITH TIES &#8230; ORDER BY ROW_NUMBER OVER (PARTITION BY &#8230;.) operation, as it is not only faster (with the correct indexes), but it doesn&#8217;t take the lifetime of an average main sequence star to compute, and it is not a hack.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER – Interview Questions and Answers – Frequently Asked Questions – Data Warehouseing Concepts – Day 20 of 31 Journey to SQLAuthority</title>
		<link>http://blog.sqlauthority.com/2010/09/22/sql-server-union-not-allowed-but-or-allowed-in-index-view-limitation-of-the-view-6/#comment-149465</link>
		<dc:creator><![CDATA[SQL SERVER – Interview Questions and Answers – Frequently Asked Questions – Data Warehouseing Concepts – Day 20 of 31 Journey to SQLAuthority]]></dc:creator>
		<pubDate>Wed, 20 Jul 2011 01:31:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=10291#comment-149465</guid>
		<description><![CDATA[[...] (Read More Here) [...]]]></description>
		<content:encoded><![CDATA[<p>[...] (Read More Here) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Duncan</title>
		<link>http://blog.sqlauthority.com/2010/09/22/sql-server-union-not-allowed-but-or-allowed-in-index-view-limitation-of-the-view-6/#comment-91460</link>
		<dc:creator><![CDATA[Duncan]]></dc:creator>
		<pubDate>Wed, 06 Oct 2010 10:25:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=10291#comment-91460</guid>
		<description><![CDATA[As I understand it, it&#039;s about updateability. If you have UNION ALL, SQL Server would need to be able to determine which branch of the UNION statement was affected by an update to one of the underlying tables. My guess is that it is tricky to do so, and therefore UNION ALL is not allowed. UNION (without the all) isn&#039;t allowed for the same reason that DISTINCT isn&#039;t allowed. That&#039;s easier to understand, since it allows a single row in the view to be decomposed from multiple branches of the UNION, so an update to any of the tables could result in extra rows in the views, or fewer. Again, a bit difficult for the query processer to, er, process.

I haven&#039;t found any definitive answers though, so can you enlighten us??!!]]></description>
		<content:encoded><![CDATA[<p>As I understand it, it&#8217;s about updateability. If you have UNION ALL, SQL Server would need to be able to determine which branch of the UNION statement was affected by an update to one of the underlying tables. My guess is that it is tricky to do so, and therefore UNION ALL is not allowed. UNION (without the all) isn&#8217;t allowed for the same reason that DISTINCT isn&#8217;t allowed. That&#8217;s easier to understand, since it allows a single row in the view to be decomposed from multiple branches of the UNION, so an update to any of the tables could result in extra rows in the views, or fewer. Again, a bit difficult for the query processer to, er, process.</p>
<p>I haven&#8217;t found any definitive answers though, so can you enlighten us??!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gifts vizag</title>
		<link>http://blog.sqlauthority.com/2010/09/22/sql-server-union-not-allowed-but-or-allowed-in-index-view-limitation-of-the-view-6/#comment-90820</link>
		<dc:creator><![CDATA[gifts vizag]]></dc:creator>
		<pubDate>Sun, 03 Oct 2010 06:09:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=10291#comment-90820</guid>
		<description><![CDATA[So far I did not think about limitation on Union as I did not work much in Views. Great article.]]></description>
		<content:encoded><![CDATA[<p>So far I did not think about limitation on Union as I did not work much in Views. Great article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marko Parkkola</title>
		<link>http://blog.sqlauthority.com/2010/09/22/sql-server-union-not-allowed-but-or-allowed-in-index-view-limitation-of-the-view-6/#comment-89057</link>
		<dc:creator><![CDATA[Marko Parkkola]]></dc:creator>
		<pubDate>Thu, 23 Sep 2010 05:01:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=10291#comment-89057</guid>
		<description><![CDATA[Just one more thing. IIRC your can update the data in indexed view with normal insert/update operation. Now because indexed view acts almost like a normal table, which is constructed from other tables, things get impossible if there&#039;s duplicate records in those tables. Which one to update?]]></description>
		<content:encoded><![CDATA[<p>Just one more thing. IIRC your can update the data in indexed view with normal insert/update operation. Now because indexed view acts almost like a normal table, which is constructed from other tables, things get impossible if there&#8217;s duplicate records in those tables. Which one to update?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2010/09/22/sql-server-union-not-allowed-but-or-allowed-in-index-view-limitation-of-the-view-6/#comment-89047</link>
		<dc:creator><![CDATA[pinaldave]]></dc:creator>
		<pubDate>Thu, 23 Sep 2010 03:19:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=10291#comment-89047</guid>
		<description><![CDATA[Great Answer.I was waiting for someone to talk about it. Another hint : Effect of Distinct on NULL.]]></description>
		<content:encoded><![CDATA[<p>Great Answer.I was waiting for someone to talk about it. Another hint : Effect of Distinct on NULL.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://blog.sqlauthority.com/2010/09/22/sql-server-union-not-allowed-but-or-allowed-in-index-view-limitation-of-the-view-6/#comment-89044</link>
		<dc:creator><![CDATA[Michael]]></dc:creator>
		<pubDate>Thu, 23 Sep 2010 03:06:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=10291#comment-89044</guid>
		<description><![CDATA[I have to figure one of the reasons that UNION isn&#039;t allowed is because DISTINCT isn&#039;t allowed, and UNION performs a DISTINCT operation automatically. But that isn&#039;t the only reason because a UNION ALL isn&#039;t allowed either.]]></description>
		<content:encoded><![CDATA[<p>I have to figure one of the reasons that UNION isn&#8217;t allowed is because DISTINCT isn&#8217;t allowed, and UNION performs a DISTINCT operation automatically. But that isn&#8217;t the only reason because a UNION ALL isn&#8217;t allowed either.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marko Parkkola</title>
		<link>http://blog.sqlauthority.com/2010/09/22/sql-server-union-not-allowed-but-or-allowed-in-index-view-limitation-of-the-view-6/#comment-89015</link>
		<dc:creator><![CDATA[Marko Parkkola]]></dc:creator>
		<pubDate>Wed, 22 Sep 2010 18:57:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=10291#comment-89015</guid>
		<description><![CDATA[Well, I came up with many reasons but when I started to think about them in depth I figured out ways to work around them. I might guess that there is no technical reason why UNION could not be used in indexed view but I would guess that it would slow down the system so much that it would negate all the positive effects of indexed view.

IIRC Microsoft has left out some features from Sql Server for performance reasons.

If you absolute want to use UNION in indexed view I came up with a workaround but it&#039;s a messy one. Create a normal table (with primary key) which is used as &quot;indexed view&quot;. Create trigger(s) to actual data table(s) and do data update &quot;by hand&quot; to the indexed-view-table. Hmmm... I think I just reinvented denormalization :)]]></description>
		<content:encoded><![CDATA[<p>Well, I came up with many reasons but when I started to think about them in depth I figured out ways to work around them. I might guess that there is no technical reason why UNION could not be used in indexed view but I would guess that it would slow down the system so much that it would negate all the positive effects of indexed view.</p>
<p>IIRC Microsoft has left out some features from Sql Server for performance reasons.</p>
<p>If you absolute want to use UNION in indexed view I came up with a workaround but it&#8217;s a messy one. Create a normal table (with primary key) which is used as &#8220;indexed view&#8221;. Create trigger(s) to actual data table(s) and do data update &#8220;by hand&#8221; to the indexed-view-table. Hmmm&#8230; I think I just reinvented denormalization :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2010/09/22/sql-server-union-not-allowed-but-or-allowed-in-index-view-limitation-of-the-view-6/#comment-88905</link>
		<dc:creator><![CDATA[pinaldave]]></dc:creator>
		<pubDate>Wed, 22 Sep 2010 06:30:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=10291#comment-88905</guid>
		<description><![CDATA[Very true. I agree.

As I said at the bottom that in this case only this works. Now try DISTINCT in Index View - it will not work. Another limitation of the VIEW!

I just think the limitations are endless.

Kind Regards,
Michael]]></description>
		<content:encoded><![CDATA[<p>Very true. I agree.</p>
<p>As I said at the bottom that in this case only this works. Now try DISTINCT in Index View &#8211; it will not work. Another limitation of the VIEW!</p>
<p>I just think the limitations are endless.</p>
<p>Kind Regards,<br />
Michael</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://blog.sqlauthority.com/2010/09/22/sql-server-union-not-allowed-but-or-allowed-in-index-view-limitation-of-the-view-6/#comment-88900</link>
		<dc:creator><![CDATA[Michael]]></dc:creator>
		<pubDate>Wed, 22 Sep 2010 05:52:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=10291#comment-88900</guid>
		<description><![CDATA[The two versions of the view aren&#039;t actually the same. With your sample data they return the same results, but for them to always return the same results you would have to add a DISTINCT to your second version:

ALTER VIEW SampleView
WITH SCHEMABINDING
AS
SELECT DISTINCT ID1,ID2,SomeData
FROM dbo.mySampleTable
WHERE ID1 &lt; 1000 OR ID2 &lt; 1000;
GO]]></description>
		<content:encoded><![CDATA[<p>The two versions of the view aren&#8217;t actually the same. With your sample data they return the same results, but for them to always return the same results you would have to add a DISTINCT to your second version:</p>
<p>ALTER VIEW SampleView<br />
WITH SCHEMABINDING<br />
AS<br />
SELECT DISTINCT ID1,ID2,SomeData<br />
FROM dbo.mySampleTable<br />
WHERE ID1 &lt; 1000 OR ID2 &lt; 1000;<br />
GO</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: siva</title>
		<link>http://blog.sqlauthority.com/2010/09/22/sql-server-union-not-allowed-but-or-allowed-in-index-view-limitation-of-the-view-6/#comment-88882</link>
		<dc:creator><![CDATA[siva]]></dc:creator>
		<pubDate>Wed, 22 Sep 2010 02:07:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=10291#comment-88882</guid>
		<description><![CDATA[Hi Pinal Dev,

I am not understand 

altered view then the clusted index is created why ?

what is the reason. could you please explaine any body.



Tx]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal Dev,</p>
<p>I am not understand </p>
<p>altered view then the clusted index is created why ?</p>
<p>what is the reason. could you please explaine any body.</p>
<p>Tx</p>
]]></content:encoded>
	</item>
</channel>
</rss>
