<?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>&#8235;Madeira &#187; צ&#8217;יקו דרורי&#8236;</title>	<atom:link href="http://www.madeira.co.il/author/chico/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.madeira.co.il</link>
	<description>&#8235;SQL Server Services&#8236;</description>	<lastBuildDate>Sat, 19 May 2012 09:04:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>he</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>&#8235;SQL Server: DateTime vs DateTime2&#8236;</title>		<link>http://www.madeira.co.il/sql-server-datetime-vs-datetime2/</link>
		<comments>http://www.madeira.co.il/sql-server-datetime-vs-datetime2/#comments</comments>
		<pubDate>Mon, 27 Feb 2012 15:08:30 +0000</pubDate>
		<dc:creator>&#8235;צ'יקו דרורי&#8236;</dc:creator>				<category><![CDATA[בלוגים]]></category>
		<category><![CDATA[כללי]]></category>
		<category><![CDATA[מאמרים]]></category>
		<category><![CDATA[מקודמות]]></category>
		<category><![CDATA[Data Types]]></category>
		<category><![CDATA[Datetime]]></category>
		<category><![CDATA[datetime2]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/?p=4444</guid>
		<description><![CDATA[&#8235;DateTime2 is the new Data Type introduced in SQL Server 2008 for storing Date and Time value that come to replace the DateTime Data Type. Want to now the difference, a little confused where to use what it's all inside&#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><p><img src='http://www.madeira.co.il/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/4444.jpg&amp;w=214&amp;h=129&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p dir="ltr"><span style="font-size: small">DateTime2 is the new Data Type introduced in SQL Server 2008 for storing Date and Time value. Microsoft Suggests to use this new Data Type instead of DateTime that is mainly available for backwards compatibility. BOL says: </span></p>
<blockquote>
<p dir="ltr"><span style="font-size: small">&quot;Use the time, date, datetime2 and datetimeoffset data types for new work”</span></p>
</blockquote>
<p dir="ltr"><span style="font-size: small">Since I can't see when in the near future DateTime will be removed from the product, I thought I'd highlight the main differences between DateTime and DateTime2.</span></p>
<h2 style="text-align: left"><span style="font-size: medium">Min\Max value</span></h2>
<p dir="ltr"><strong><span style="font-size: small">DateTime  -<span style="color: #ff0000"> </span></span></strong></p>
<p dir="ltr"><span style="font-size: small"><span style="color: #ff0000"><span style="color: #a5a5a5">BETWEEN</span> ‘1753-01-01 00:00:00’ </span><span style="color: #a5a5a5">AND '</span><span style="color: #ff0000">’9999-12-31 23:59:59.997’</span></span></p>
<p dir="ltr"><strong><span style="font-size: small">DateTime2 &#8211; </span></strong></p>
<p dir="ltr"><span style="font-size: small"><span style="color: #ff0000"><span style="color: #a5a5a5">BETWEEN</span> ‘0001-01-01 00:00:00’ </span><span style="color: #a5a5a5">AND </span><span style="color: #ff0000">‘9999-12-31 23:59:59.9999999’</span></span></p>
<h2 style="text-align: left"><span style="font-size: medium">Storage Size</span></h2>
<p dir="ltr"><span style="font-size: small"><strong>DateTime  -</strong> 8 Bytes</span></p>
<p dir="ltr"><span style="font-size: small"><strong>DateTime2(n) -</strong> 6 to 8 bytes </span></p>
<p dir="ltr"><span style="font-size: small"><strong>Note:</strong> Parameter n is optional and if it is not specified then fractional seconds precision is 7 digit and it can be from 0 to 7 digit. </span></p>
<p><span style="font-size: small"> </span></p>
<p dir="ltr">For fractional seconds precision &lt;3, takes 6 bytes.</p>
<p dir="ltr">For fractional seconds precision 3 or 4 it will take 7 bytes.</p>
<p dir="ltr"><span style="font-size: small">For fractional seconds precision &gt;4 it will take 8 bytes.</span></p>
<h2 style="text-align: left"><span style="font-size: medium">Precision</span></h2>
<p dir="ltr"><span style="font-size: small"><strong>DateTime  -</strong> only allows for precision up to every 3rd milisecond which essentially means that you can get rounding issues for times that are in fact different. The rounding is to increments of .000, .003, or .007 seconds.</span></p>
<p dir="ltr"><span style="font-size: small"><strong>DateTime2(n) -</strong> The precision scale is 0 to 7 digits, with an accuracy of 100 nanoseconds . The default precision is 7 digits.</span></p>
<p dir="ltr"><span style="color: #000000"><span style="font-size: small"><strong>Note:</strong> DateTime2 with fractional seconds precision of 3 is same as DateTime data type. And DateTime2(3) uses 7 bytes of storage instead of 8 byte which old DateTime datatype uses.</span></span></p>
<h2 style="text-align: left"><span style="font-size: medium">conclusion</span></h2>
<p dir="ltr"><span style="font-size: small">I believe we should follow MSDN recommendation and use DateTime2 for any new work and thus, we will be safeguarded against future changes and benefit from a larger date range, less storage uses,larger default fractional precision, and optional user-specified precision.</span></p>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/sql-server-datetime-vs-datetime2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>&#8235;The Dedicated administrator connection&#8236;</title>		<link>http://www.madeira.co.il/the-dedicated-administrator-connection/</link>
		<comments>http://www.madeira.co.il/the-dedicated-administrator-connection/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 20:53:25 +0000</pubDate>
		<dc:creator>&#8235;צ'יקו דרורי&#8236;</dc:creator>				<category><![CDATA[בלוגים]]></category>
		<category><![CDATA[כללי]]></category>
		<category><![CDATA[מאמרים]]></category>
		<category><![CDATA[מקודמות]]></category>
		<category><![CDATA[DAC]]></category>
		<category><![CDATA[Dedicated administrator connection]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>
		<category><![CDATA[Troubleshooting]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/?p=4044</guid>
		<description><![CDATA[&#8235;Ever been in a crisis that your SQL Server didn’t respond to standard connection requests? thought that your  last resort was to reboot the  server? This probably because you either haven’t met or forgotten to turn on the DAC your secret backdoor connection to SQL Server&#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><p><img src='http://www.madeira.co.il/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/4044.png&amp;w=214&amp;h=129&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p dir="ltr"><span style="font-size: small">Ever been in a crisis that your SQL Server had a spinloop, maxed out resources or severe corruption and  didn’t respond to standard connection requests, and  With pressure mounting to get SQL Server back online you thought that your  last resort was to reboot the server?</span></p>
<p dir="ltr"><span style="font-size: small">This probably because you either haven’t met or forgotten to turn on the<strong> DAC</strong> your secret backdoor Privilege connection that SQL server offers to us.</span></p>
<h5 style="text-align: left"><span style="font-weight: bold;font-size: medium">DAC? What’s That?</span></h5>
<p dir="ltr"><span style="font-size: small">Since SQL Server 2005, Microsoft offers us new feature, the dedicated administrator connection (DAC) a special diagnostic connection for administrators. This diagnostic connection intended to serve as a last means of defense and access SQL Server to execute diagnostic queries and troubleshoot problems even when SQL Server is not responding to standard connection requests as opposed to rebooting the server and causing us long downtime and  possibly data loss, database corruption and/or access violations. </span></p>
<h5 style="text-align: left"><strong><span style="font-size: small"><span style="font-size: medium">How the DAC works</span> </span></strong></h5>
<p dir="ltr"><span style="font-size: small">SQL Server is keeping a backdoor open  resources available just for the DAC, it uses a<span style="color: #0000ff"> </span></span><a href="http://msdn.microsoft.com/en-us/library/ms177526.aspx"><span style="color: #0000ff;font-size: small">special reserved scheduler</span></a><span style="font-size: small"> (scheduler_id = 255)  which has one thread for processing requests.</span></p>
<p dir="ltr"><span style="font-size: small">We are all DBA’s and I know that to many of you the thought of abuse thus resources for your maintenance jobs on busy systems cross your mind. Seriously, just don’t go there.That one thread is just one thread, there’s no parallelism for queries running on the DAC. The DAC was not designed for high performance.</span></p>
<h5 style="text-align: left"><span style="font-weight: bold;font-size: medium">some restrictions</span></h5>
<p dir="ltr"><span style="font-size: small">Because the DAC exists solely for diagnosing server problems, there are some restrictions on the connection:</span></p>
<div style="line-height: normal;margin-top: 12pt;text-indent: -0.5in;direction: ltr;margin-bottom: 0pt;margin-left: 0.5in"><strong><span style="color: #000000"><span style="font-size: small"><span>Only </span><span>member of </span><span>sysadmin</span><span> </span><span>role </span><span>can </span><span>use </span><span>DAC.</span></span></span></strong></div>
<p dir="ltr"><strong><span style="font-size: small">Only One Sysadmin Can Ride This Horse At a Time.</span></strong></p>
<p dir="ltr"><span style="font-size: small"><strong>SQL Server prohibits running parallel queries or commands with the DAC -</strong> For example statements like RESTORE and BACKUP.</span></p>
<p dir="ltr"><span style="font-size: small"><strong>Do not use the DAC to run resource-intensive queries -</strong> For example a complex join on large table or queries that may block.</span></p>
<p dir="ltr"><span style="font-size: small"><strong>Object Explorer Not available for DAC connection -</strong> That’s a good thing, we wouldn’t want the power to go to Object Explorer’s head.</span></p>
<h5 style="text-align: left"><strong><span style="font-size: medium">Connecting with DAC</span></strong></h5>
<p dir="ltr"><span style="font-size: small">By default, the connection is only allowed  from a client running on the local machine. To enable remote clients to utilize the DAC, an option needs to be <span style="color: #333333">set</span><span style="color: #333333"> which can be done using <span style="color: #d16349">sp_configure</span>:</span></span></p>
<div style="text-align: left;padding: 4px;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 97.71%;font-family: 'Courier New',courier,monospace;direction: ltr;height: 52px;font-size: 8pt;overflow: auto;cursor: text;border: 1px solid silver">
<div style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible">
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Arial"><span style="font-size: small"><span style="color: #606060">   1:</span> <span style="color: #0000ff">exec</span> sp_configure <span style="color: #006080">'remote admin connections'</span>, 1 </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Arial"><span style="font-size: small"><span style="color: #606060">   2:</span> <span style="color: #0000ff">reconfigure</span></span></span></pre>
<p><!--CRLF--></p>
</div>
</div>
<p dir="ltr"><span style="font-size: small">it’s Highly recommended to enable the ‘remote admin connections’, Especially on clusters configuration. According to BOL servers in cluster configuration and with ‘remote admin connections’ not enable probably Not receive a DAC connection And you can not escape from rebooting the server.</span></p>
<p dir="ltr"><span style="font-size: small">You may need to get firewall ports opened as well, depending on your environment and where you intend to connect from. SQL Server listens for the DAC on TCP port 1434 if available or a TCP port dynamically assigned upon Database Engine startup. The error log contains the port number the DAC is listening on.</span></p>
<p dir="ltr"><strong><span style="font-size: small">To use the DAC you can either access it using<span style="color: #0000ff"> </span></span></strong><a href="http://msdn2.microsoft.com/en-us/ms170207.aspx"><span style="color: #0000ff;font-size: small"><strong>SQLCMD</strong></span></a><strong><span style="font-size: small"> from a command prompt:</span></strong></p>
<p dir="ltr"><span style="font-size: small"><strong>sqlcmd –A –d master </strong>(the -A uses the DAC and the -d connects to the master database) </span></p>
<p dir="ltr"><span style="font-size: small"><strong>sqlcmd –d DBname-E –S ServerName\InstanceName –A</strong> (the -E uses Windows authentication and the -S connects the server and instance)</span></p>
<p dir="ltr"><a href="$Picture1[7].png"><span style="font-size: small"> </span></a><a href="http://www.madeira.co.il/wp-content/uploads/2012/01/Picture1.png" rel="wp-prettyPhoto[g4044]"><img class="aligncenter size-medium wp-image-4053" src="http://www.madeira.co.il/wp-content/uploads/2012/01/Picture1-300x57.png" alt="" width="300" height="57" /></a></p>
<p dir="ltr"><strong><span style="font-size: small">Or The more convenient way is using SQL Management Studio with the ADMIN: option when connecting to the server:</span></strong></p>
<p dir="ltr"><span style="font-size: small">- launch SQL Server Management Studio (don't connect to an instance of SQL Server yet) </span></p>
<p dir="ltr"><span style="font-size: small">- <strong>select Database Engine Query (icon right next to &quot;New Query&quot;) </strong></span></p>
<p dir="ltr"><span style="font-size: small">- <strong>put &quot;ADMIN:&quot; in front of the server\instance name </strong></span></p>
<p dir="ltr"><span style="font-size: small">- <strong>use your regular Authentication procedures to connect </strong></span></p>
<p dir="ltr"><span style="font-size: small">- <strong>select Connect</strong></span></p>
<p dir="ltr"><a href="$Picture2[9].png"><span style="font-size: small"> </span></a><a href="http://www.madeira.co.il/wp-content/uploads/2012/01/Picture2.png" rel="wp-prettyPhoto[g4044]"><img class="aligncenter size-medium wp-image-4054" src="http://www.madeira.co.il/wp-content/uploads/2012/01/Picture2-300x196.png" alt="" width="300" height="196" /></a></p>
<p dir="ltr"><span style="font-size: small"><strong>Note:</strong> Object Explorer can’t connect to the DAC. If you open SSMS and have Object Explorer connecting by default, the first connection prompt you see with be for that. If you try to tell that to connect to the DAC, it’ll fail.</span></p>
<h5 style="text-align: left"><span style="font-size: medium"><span style="font-weight: bold"> </span><span style="font-weight: bold">conclusion </span></span></h5>
<p dir="ltr"><span style="font-size: small">In previous versions of SQL Server it was often not possible to diagnose a SQL Server instance which was no longer accepting connections. With DAC an administrator has a guaranteed connection to the SQL Server, and is able to resolve problems without the need for a reboot, or restarting the SQL server instance.</span></p>
<p dir="ltr"><span style="font-size: small">For now check whether you have remote admin connections enabled in your environments and try to connect with the DAC in test environment </span></p>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/the-dedicated-administrator-connection/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#8235;SQL Server Indexed View&#8236;</title>		<link>http://www.madeira.co.il/sql-server-indexed-view-2/</link>
		<comments>http://www.madeira.co.il/sql-server-indexed-view-2/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 02:11:06 +0000</pubDate>
		<dc:creator>&#8235;צ'יקו דרורי&#8236;</dc:creator>				<category><![CDATA[בלוגים]]></category>
		<category><![CDATA[כללי]]></category>
		<category><![CDATA[מקודמות]]></category>
		<category><![CDATA[Indexed View]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/?p=3565</guid>
		<description><![CDATA[&#8235;Indexed Views can really provide enormous preformance benefits under the right circumstances and the right use. Learn what indexed views are, where and when you might want to use them, how to create them, and what constraints exist with their use   &#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><p><img src='http://www.madeira.co.il/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/3565.jpg&amp;w=214&amp;h=129&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">For many years, Microsoft SQL Server has supported the ability to create virtual tables known as views. Historically, these view served these main purposes:</span></p>
<p dir="ltr"><span style="font-family: Calibri"><span style="font-size: small">-<strong>provide a security mechanism that restricts users to a certain subset of data in one or more base tables</strong></span></span></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-To provide a mechanism that allows developers to customize how users can logically view the data stored in base tables</span></strong></p>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">When you create a view, you add a stored query to the database that can be read in the same manner as a table. The view acts as a virtual table that requires no additional storage space, as the information is read directly from the tables.</span></p>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">A view's performance can be significantly worse than that of a table, particularly when the view reads from several, joined tables<em>. </em>With SQL Server 2000, the functionality of SQL Server views was expanded to provide system performance benefits. It is possible to create a unique clustered index on a view, as well as non-unique and non-clustered indexes but only if a unique, clustered index exists , to improve data access performance on the most complex queries by precomputing and materializing the view. This is often particularly effective for aggregate views in decision support or data warehouse environments.</span></p>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">Creating a unique clustered index on a view changes it to an indexed view. The clustered index is stored in SQL Server and updated like any other clustered index, providing SQL Server with another place to look to potentially optimize a query utilizing the indexed view. </span></p>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">When the first index is added to a view, it is built using a b-tree structure similar to that of a table index. The b-tree includes the data from the columns that are present in the index. However, unlike a table index, all of the columns that are included in the view are also added to the data rows of the index. This can lead to large increases in the storage requirements for a database but improves the view's performance.</span></p>
<p dir="ltr"><span style="font-family: Calibri"><span style="font-size: small">Queries that don’t specifically use the indexed view can even benefit from the existence of the clustered index from the view. In the<strong> developer and enterprise editions</strong> of SQL Server, the optimizer can use the indexes of views to optimize queries that do not specify the indexed view. <strong>In the other editions of SQL Server, however, the query must include the indexed view and specify the hint NOEXPAND to get the benefit of the index on the view.</strong></span></span></p>
<p dir="ltr"><strong><span style="font-family: Calibri;color: #ff0000;font-size: small"><span style="text-decoration: underline">Advantages of Indexed View</span></span></strong></p>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">Indexed views improve the performance in the following ways:</span></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-Joins and aggregations that process many rows. </span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-Join and aggregation operations that are frequently performed by  many queries. </span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-Decision support workloads. </span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-The real benefits of Indexed Views are when we have aggregates that are too expensive to compute in real time. </span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-Aggregations can be pre-computed and stored in the index to minimize expensive computations during query execution. </span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-Tables can be pre-joined and the resulting data set stored. </span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-Combinations of joins or aggregations can be stored. </span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-Indexed views may be substituted by the query optimizer if it is determined that the cost of the query will be less than using the base table. </span></strong></p>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">For a standard view, the overhead of dynamically building the result set for each query that references a view can be significant for views that involve complex processing of large numbers of rows, such as aggregating lots of data, or joining many rows. If such views are frequently referenced in queries, we can improve performance by creating a unique clustered index on the view. When a unique clustered index is created on a view, the result set is stored in the database just like a table with a clustered index is stored. </span></p>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">Another benefit of creating an index on a view is that the optimizer starts using the view index in queries that do not directly name the view in the FROM clause. Existing queries can benefit from the improved efficiency of retrieving data from the indexed view without having to be recoded.</span></p>
<p dir="ltr"><strong><span style="font-family: Calibri;color: #ff0000;font-size: small"><span style="text-decoration: underline">Disadvantages of Indexed View</span></span></strong></p>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">To use an indexed view in all other editions, the NOEXPAND table hint must be used. Indexed views work best when the underlying data is infrequently updated. The maintenance of an indexed view can be greater than the cost of maintaining a table index. If the underlying data is updated frequently, the cost of maintaining the indexed view data may outweigh the performance benefits of using the indexed view.</span></p>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">Another cost of indexed views is that the data is actually stored. By applying the clustered index we are creating a copy of the data. So if we have several indexed views on a single table, we will have several copies of the data, along with the statistics of the data and the indexes and all of the overhead that goes with it.</span></p>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">Following are the disadvantages using index views that do not improve the performance: </span></p>
<p dir="ltr">
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-OLTP systems that have many writes to the disk. </span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-Databases that have many updates. </span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-Queries that do not involve aggregations or joins. </span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-High numbers of updates will most likely kill the benefit. If it is mainly reads then it will work fine. </span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-The overuse of indexed views can be like winding a watch with a wrench. </span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-Online index rebuilds are not supported for indexed views. </span></strong></p>
<h5 style="text-align: left"><span style="color: #ff0000"><span style="font-weight: bold;font-family: Calibri;font-size: small"><span style="text-decoration: underline">Limitations and Constraints of Indexed View</span></span></span></h5>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">An index cannot be created on just any view. Several limitations and constraints exist that a view must meet in order for the index creation to be successful. The key restrictions\Constraints are listed below:</span></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-The base tables must have been created with the proper ANSI_NULLS setting.</span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-The view must have been created with certain SET options, such as QUOTED_IDENTIFIER and CONCAT_NULL_YIELDS_NULL set to ON.</span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-Indexed views must be created using the SCHEMABINDING option. This option links the view to the schema elements that it uses, disallowing changes to the underlying tables that would break the view. If the   view references user-defined functions, these too must be created using the option.</span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-Indexed views may only select columns from base tables. They may not retrieve values from other views. The tables must be in the same database as the view and must have the same owner.</span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-The view must be deterministic (consistently providing the same result given  the same input). </span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;font-size: small">-Any user-defined functions referenced by the view must have been created using WITH SCHEMABINDING and to be deterministic.</span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri"><span style="font-size: small">-On the content  of the view Must also meet with some requirements For instance, the view may not contain <span style="color: #666666">EXISTS</span> or <span style="color: #666666">NOT EXISTS</span>, <span style="color: #666666">OUTER JOIN</span>, <span style="color: #ff00ff">COUNT</span>(*), <span style="color: #ff00ff">MIN</span><span style="color: #000000">()</span>, <span style="color: #ff00ff">MAX</span><span style="color: #000000">()</span>, subqueries, table <span style="color: #0000ff">hints</span>, <span style="color: #666666">TOP</span>, <span style="color: #0000ff">UNION</span><span style="color: #000000">.</span></span></span></strong></p>
<p dir="ltr"><strong><span style="font-family: Calibri;color: #000000;font-size: small">-The result set of the view is physically stored in the database, thus storage space for the clustered index is also a constraint to consider.</span></strong></p>
<p><strong> </strong></p>
<p dir="ltr"><span style="font-family: Calibri;color: #ff0000;font-size: small"><strong><span style="text-decoration: underline">creating indexed view</span></strong></span></p>
<p dir="ltr"><span style="font-family: Calibri;color: #000000;font-size: small">First let’s create some tables and put data into them:</span></p>
<div class="csharpcode-wrapper">
<div class="csharpcode" dir="ltr">
<div style="text-align: left;padding: 4px;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 97.5%;font-family: 'Courier New',courier,monospace;direction: ltr;font-size: 8pt;overflow: auto;cursor: text;border: 1px solid silver">
<div style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible">
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">   1:</span> <span style="color: #0000ff">CREATE</span> <span style="color: #0000ff">TABLE</span> dbo.employees</span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">   2:</span>     (</span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">   3:</span>         id <span style="color: #0000ff">int</span> <span style="color: #0000ff">NOT</span> <span style="color: #0000ff">NULL</span>, </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">   4:</span>         name <span style="color: #0000ff">varchar</span>(255) <span style="color: #0000ff">NOT</span> <span style="color: #0000ff">NULL</span>, </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">   5:</span>         <span style="color: #0000ff">CONSTRAINT</span> PK_employees <span style="color: #0000ff">PRIMARY</span> <span style="color: #0000ff">KEY</span> (id), </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">   6:</span>         <span style="color: #0000ff">CONSTRAINT</span> UQ_employees <span style="color: #0000ff">UNIQUE</span> (name)</span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">   7:</span>     ) <span style="color: #0000ff">ON</span> <span style="color: #0000ff">PRIMARY</span></span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">   8:</span>  </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">   9:</span> <span style="color: #0000ff">CREATE</span> <span style="color: #0000ff">TABLE</span> dbo.roles</span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  10:</span>     (</span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  11:</span>         id <span style="color: #0000ff">int</span> <span style="color: #0000ff">NOT</span> <span style="color: #0000ff">NULL</span>, </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  12:</span>         name <span style="color: #0000ff">varchar</span>(255) <span style="color: #0000ff">NOT</span> <span style="color: #0000ff">NULL</span>, </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  13:</span>         <span style="color: #0000ff">CONSTRAINT</span> PK_roles <span style="color: #0000ff">PRIMARY</span> <span style="color: #0000ff">KEY</span> (id), </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  14:</span>         <span style="color: #0000ff">CONSTRAINT</span> UQ_roles <span style="color: #0000ff">UNIQUE</span> (name)</span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  15:</span>     ) <span style="color: #0000ff">ON</span> <span style="color: #0000ff">PRIMARY</span></span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  16:</span>  </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  17:</span> <span style="color: #0000ff">CREATE</span> <span style="color: #0000ff">TABLE</span> dbo.lnk_employee_roles</span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  18:</span>     (</span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  19:</span>         employee_id <span style="color: #0000ff">int</span> <span style="color: #0000ff">NOT</span> <span style="color: #0000ff">NULL</span>, </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  20:</span>         role_id <span style="color: #0000ff">int</span> <span style="color: #0000ff">NOT</span> <span style="color: #0000ff">NULL</span>, </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  21:</span>         <span style="color: #0000ff">CONSTRAINT</span> PK_lnk_employee_roles <span style="color: #0000ff">PRIMARY</span> <span style="color: #0000ff">KEY</span> (employee_id, role_id), </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  22:</span>         <span style="color: #0000ff">CONSTRAINT</span> FK_lnk_employee_roles__employees <span style="color: #0000ff">FOREIGN</span> <span style="color: #0000ff">KEY</span> (employee_id) <span style="color: #0000ff">REFERENCES</span> dbo.employees (id), </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  23:</span>         <span style="color: #0000ff">CONSTRAINT</span> FK_lnk_employee_roles__roles <span style="color: #0000ff">FOREIGN</span> <span style="color: #0000ff">KEY</span> (role_id) <span style="color: #0000ff">REFERENCES</span> dbo.roles (id)</span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  24:</span>     ) <span style="color: #0000ff">ON</span> <span style="color: #0000ff">PRIMARY</span></span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  25:</span>  </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  26:</span> INSERT <span style="color: #0000ff">INTO</span> dbo.employees (id, name)</span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  27:</span> <span style="color: #0000ff">VALUES</span> </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  28:</span>     (1, <span style="color: #006080">'Employee 1'</span>), </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  29:</span>     (2, <span style="color: #006080">'Employee 2'</span>), </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  30:</span>     (3, <span style="color: #006080">'Employee 3'</span>)</span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  31:</span>  </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  32:</span> INSERT <span style="color: #0000ff">INTO</span> dbo.roles (id, name)</span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  33:</span> <span style="color: #0000ff">VALUES</span> </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  34:</span>     (1, <span style="color: #006080">'Role 1'</span>), </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  35:</span>     (2, <span style="color: #006080">'Role 2'</span>), </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  36:</span>     (3, <span style="color: #006080">'Role 3'</span>)</span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  37:</span>  </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  38:</span> INSERT <span style="color: #0000ff">INTO</span> lnk_employee_roles (employee_id, role_id)</span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  39:</span> <span style="color: #0000ff">VALUES</span> </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  40:</span>     (1, 1), </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  41:</span>     (1, 2), </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  42:</span>     (1, 3), </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  43:</span>     (3, 2), </span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  44:</span>     (3, 3)</span></span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="font-family: Calibri"><span style="font-size: x-small"><span style="color: #606060">  45:</span> GO</span></span></pre>
<p><!--CRLF--></p>
</div>
</div>
<div dir="ltr"><span class="lnum"><span style="font-family: Calibri;font-size: small">Now let’s create a view but we need to remember A view that Intended to be indexed has to be created with schema binding. This means that once the indexed view is created, the underlying tables cannot be altered in any way that would materially affect the indexed view unless the view is first altered or dropped. It also means that all the tables referenced in the view must be referenced by their two-part name (schemaname.tablename):</span></span></div>
<div dir="ltr"><span class="lnum"> </span></div>
<div style="text-align: left;padding: 4px;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 97.5%;font-family: 'Courier New',courier,monospace;direction: ltr;font-size: 8pt;overflow: auto;cursor: text;border: 1px solid silver">
<div style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible">
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">   1:</span> <span style="color: #0000ff">CREATE</span> <span style="color: #0000ff">VIEW</span> dbo.EmployeeRoles</pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">   2:</span> <span style="color: #0000ff">WITH</span> SCHEMABINDING</pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">   3:</span> <span style="color: #0000ff">AS</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">   4:</span> <span style="color: #0000ff">SELECT</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">   5:</span>     e.id <span style="color: #0000ff">as</span> employee_id,</pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">   6:</span>     e.name <span style="color: #0000ff">as</span> employee_name,</pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">   7:</span>     r.id <span style="color: #0000ff">as</span> role_id,</pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">   8:</span>     r.name <span style="color: #0000ff">as</span> role_name</pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">   9:</span> <span style="color: #0000ff">FROM</span></pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">  10:</span>     dbo.employees e</pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">  11:</span>         <span style="color: #0000ff">INNER</span> <span style="color: #0000ff">JOIN</span> dbo.lnk_employee_roles er <span style="color: #0000ff">ON</span> e.id = er.employee_id</pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">  12:</span>         <span style="color: #0000ff">INNER</span> <span style="color: #0000ff">JOIN</span> dbo.roles r <span style="color: #0000ff">ON</span> r.id = er.role_id</pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">  13:</span> GO</pre>
<p><!--CRLF--></p>
</div>
</div>
<pre><span style="font-family: Calibri"><span style="font-size: small"><span class="lnum"> </span><span style="color: #000000"> And finally let’s create the unique clustered index on the view </span></span></span><span style="font-family: Calibri;font-size: small">making it an indexed view:</span></pre>
</div>
</div>
<div style="text-align: left;padding: 4px;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 97.5%;font-family: 'Courier New',courier,monospace;direction: ltr;font-size: 8pt;overflow: auto;cursor: text;border: 1px solid silver">
<div style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible">
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">   1:</span> <span style="color: #0000ff">CREATE</span> <span style="color: #0000ff">UNIQUE</span> <span style="color: #0000ff">CLUSTERED</span> <span style="color: #0000ff">INDEX</span> idx_EmployeeRoles</pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">   2:</span> <span style="color: #0000ff">ON</span> dbo.EmployeeRoles (employee_id, role_id)</pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">   3:</span> <span style="color: #0000ff">ON</span> INDEXES</pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">   4:</span> GO</pre>
<p><!--CRLF--></p>
</div>
</div>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">Notice that I create the clustered index on anther filegroup, </span><span style="font-family: Calibri;font-size: small">it to be very useful to store indexes in their own filegroup, especially Indexed Views.</span><span style="font-family: Calibri;font-size: small"> </span></p>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">What this means is that the base data (data in base tables) lives on one filegroup and the data for the indexes lives on another filegroup. If these filegroups live on separate storage (ideally separate hard drives with seperate controllers), writes to the base table do not contend with writes to the indexes.</span></p>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">Now let’s see the performance, check out the execution plan for the following query: </span></p>
<p dir="ltr">
<div>
<div style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible">
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">   1:</span> <span style="color: #0000ff">SELECT</span> employee_name, role_name <span style="color: #0000ff">FROM</span> dbo.EmployeeRoles</pre>
<p><!--CRLF--></p>
</div>
</div>
<p dir="ltr"><a href="$1[2].png"></a></p>
<p><a href="$1[2].png"></a></p>
<div class="mceTemp mceIEcenter">
<dl><a href="$1[2].png"></a></p>
<dt><a href="$1[2].png"></a><a href="http://www.madeira.co.il/wp-content/uploads/2012/01/1.png" rel="wp-prettyPhoto[g3565]"><img class="size-medium wp-image-3567" src="http://www.madeira.co.il/wp-content/uploads/2012/01/1-300x139.png" alt="" width="300" height="139" /></a></dt>
<dd>Execution Plan</dd>
</dl>
</div>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">You'll see an index scan on employees.UQ_<em>employees and lnk_</em>employee<em>roles.PK_</em>lnk_<em>employee</em>roles, plus a Clustered Index Seek on roles.PK_roles.</span></p>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">Now let’s use the Indexed Views and  compare the  execution plans, run that  query:</span></p>
<div>
<div style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible">
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">   1:</span> <span style="color: #0000ff">SELECT</span> employee_name, role_name</pre>
<p><!--CRLF--></p>
<pre style="border-style: none;text-align: left;padding: 0px;line-height: 12pt;background-color: #f4f4f4;margin: 0em;width: 100%;font-family: 'Courier New',courier,monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible"><span style="color: #606060">   2:</span> <span style="color: #0000ff">FROM</span> dbo.EmployeeRoles <span style="color: #0000ff">WITH</span> (NOEXPAND)</pre>
<p><!--CRLF--></p>
</div>
</div>
<div class="mceTemp mceIEcenter"><a href="$2[2].png"></a></p>
<dl><a href="$2[2].png"></a></p>
<dt><a href="$2[2].png"></a><a href="http://www.madeira.co.il/wp-content/uploads/2012/01/2.png" rel="wp-prettyPhoto[g3565]"><img class="size-medium wp-image-3568" src="http://www.madeira.co.il/wp-content/uploads/2012/01/2-300x80.png" alt="" width="300" height="80" /></a></dt>
<dd>Execution Plan</dd>
</dl>
</div>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">You'll see only a clustered index scan on <strong>EmployeeRoles.idx_EmployeeRoles</strong> that provid better performance.</span></p>
<h4 style="text-align: left"><span style="color: #ff0000"><span style="text-decoration: underline">Conclusion</span></span></h4>
<p dir="ltr"><span style="font-family: Calibri;font-size: small">Using Indexed view in SQL Server comes with a cost. But there are places which it perfectly fits and gains up the performance. Be aware of the costs of creating indexed views in highly transactional environments. If your environment happens to be one of more querying than updating, however, indexed views might be just what the optimizer ordered. </span></p>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/sql-server-indexed-view-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

