{"id":10884,"date":"2019-03-24T09:19:46","date_gmt":"2019-03-24T09:19:46","guid":{"rendered":"https:\/\/dbtut.com\/?p=10884"},"modified":"2019-03-24T19:20:05","modified_gmt":"2019-03-24T19:20:05","slug":"what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view","status":"publish","type":"post","link":"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/","title":{"rendered":"What is Indexed View in SQL Server and How To Create an Indexed View"},"content":{"rendered":"<p>We create Indexed Views by adding indexes to views. For detailed information about the View concept, I would recommend you read my article &#8220;<a href=\"https:\/\/dbtut.com\/index.php\/2019\/03\/21\/what-is-view-in-sql-server-and-how-to-create-a-view\/\" target=\"_blank\" rel=\"noopener noreferrer\">What is View in SQL Server and How to Create a View<\/a>&#8220;.<\/p>\n<p>Views does not store data. When we convert the views to indexed view, they start to store the data. Therefore, the performance of the view is increased while the insert, update, and delete performances of the tables selected by the view decrease. Also indexed views begin to take up extra space in your database. There are some conditions-restrictions for converting views to indexed view. Let&#8217;s examine these conditions.<\/p>\n<h2>Condition 1: WITH SHEMABINDING<\/h2>\n<p>You must use WITH SHEMABINDING Clause when creating view.<\/p>\n<h3>What is Schemabinding?<\/h3>\n<p>When you set View as schemabinding, DML operations cannot be performed in the tables that View selects.<\/p>\n<p>After you create the view in the schemabinding structure, if you perform a DML operation in the columns in the tables that the view selects, you will receive an error as follows.<\/p>\n<h3>Create a SCHEMABINDING VIEW<\/h3>\n<pre class=\"lang:default decode:true\">USE [TestDB]\nGO\nCREATE VIEW [dbo].[IndexedViewExample]\nWITH SCHEMABINDING AS\nSELECT [ID],[Name] FROM [dbo].[MyTable]\nGO<\/pre>\n<h3>Convert a VIEW To SCHEMABINDING VIEW<\/h3>\n<pre class=\"lang:default decode:true \">USE [TestDB]\nGO\nALTER VIEW [dbo].[IndexedViewExample]\nWITH SCHEMABINDING AS\nSELECT [ID],[Name] FROM [dbo].[MyTable]\nGO<\/pre>\n<h3>ALTER the column that the SCHEMABINDING VIEW Selects<\/h3>\n<pre class=\"lang:default decode:true \">USE [TestDB]\nGO\nALTER TABLE [dbo].[MyTable]\nALTER COLUMN ID bigint;\n<\/pre>\n<p style=\"margin: 0in; font-family: Georgia; font-size: 12.0pt;\"><span style=\"color: #ff0000;\"><em>Msg 5074, Level 16, State 1, Line 3<\/em><\/span><\/p>\n<p style=\"margin: 0in; font-family: Georgia; font-size: 12.0pt;\"><span style=\"color: #ff0000;\"><em>The object &#8216;IndexedViewExample&#8217; is dependent on column &#8216;ID&#8217;.<\/em><\/span><\/p>\n<p style=\"margin: 0in; font-family: Georgia; font-size: 12.0pt;\"><span style=\"color: #ff0000;\"><em>Msg 4922, Level 16, State 9, Line 3<\/em><\/span><\/p>\n<p style=\"margin: 0in; font-family: Georgia; font-size: 12.0pt;\"><span style=\"color: #ff0000;\"><em>ALTER TABLE ALTER COLUMN ID failed because one or more objects access this column.<\/em><\/span><\/p>\n<p id=\"AsCTJfx\"><img loading=\"lazy\" decoding=\"async\" width=\"783\" height=\"315\" class=\"size-full wp-image-10890 aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/03\/img_5c963321488b4.png\" alt=\"\" \/><\/p>\n<h2>Condition 2: * FROM<\/h2>\n<p>You must write the columns individually instead of &#8220;* FROM&#8221; in the Select statement that will create the View. If you do not, you will receive an error as below.<\/p>\n<p><span style=\"color: #ff0000;\"><em>Msg 1054, Level 15, State 6, Procedure IndexedViewExample, Line 4<\/em><\/span><\/p>\n<p><span style=\"color: #ff0000;\"><em>Syntax &#8216;*&#8217; is not allowed in schema-bound objects.<\/em><\/span><\/p>\n<h2>Condition 3: Create a Unique Clustered Index<\/h2>\n<p>After creating the view with schemabinding structure, you must first create a unique clustered index. After creating unique clustered index, you can create index in other columns. You can create a unique clustered index with the following script.<\/p>\n<pre class=\"lang:default decode:true \">CREATE UNIQUE CLUSTERED INDEX UIX_IndexedViewExample \n    ON dbo.IndexedViewExample(ID);   \nGO  \n<\/pre>\n<p>In our example, we chose to create unique clustered index on ID column. Make sure that the column you choose for Unique Clustered Index is unique in the table that View selects. Otherwise you will receive the below error.<\/p>\n<p><span style=\"color: #ff0000;\"><em>Msg 1505, Level 16, State 1, Line 1<\/em><\/span><\/p>\n<p><span style=\"color: #ff0000;\"><em>The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name &#8216;IndexedViewExample&#8217; and the index name &#8216;UIX_IndexedViewExample&#8217;. The duplicate key value is (182861, C740D0288EA7C45FE0407C0A04162BDD, 12685525396).<\/em><\/span><\/p>\n<p><span style=\"color: #ff0000;\"><em>The statement has been terminated.<\/em><\/span><\/p>\n<h2>Condition 4: Unavailable TSQLs<\/h2>\n<p>You cannot use the expressions specified below in your select query when creating View.<\/p>\n<ul type=\"disc\">\n<li>COUNT<\/li>\n<li>Derived tables<\/li>\n<li>float,\u00a0text,\u00a0ntext,\u00a0image,\u00a0XML, or filestream\u00a0columns<\/li>\n<li>CONTAINS and FREETEXT predicates<\/li>\n<li>CLR User-Defined Aggregate Functions<\/li>\n<li>MIN and MAX Functions<\/li>\n<li>Table variables<\/li>\n<li>Sparse columns<\/li>\n<li>ROWSET functions (OPENDATASOURCE, OPENQUERY, OPENROWSET, AND OPENXML)<\/li>\n<li>Self Joins<\/li>\n<li>Subqueries<\/li>\n<li>SUM function if it references a nullable expression<\/li>\n<li>TOP<\/li>\n<li>UNION, EXCEPT and INTERSECT Operators<\/li>\n<li>CROSS APPLY and OUTER APPLY Operators<\/li>\n<li>Table-valued functions(Inline or multi statement)<\/li>\n<li>OUTER Join Types<\/li>\n<li>Common table expression (CTE)<\/li>\n<li>OVER and ORDER BY<\/li>\n<li>CUBE, ROLLUP and GROUPING SETS Operators<\/li>\n<li>PIVOT and UNPIVOT<\/li>\n<li>OFFSET<\/li>\n<\/ul>\n<p>For example, if you use &#8220;<strong>UNION, INTERSECT, or EXCEPT<\/strong>&#8220;, you will receive an error as follows when creating the unique clustered index.<\/p>\n<p><span style=\"color: #ff0000;\"><em>Msg 10116, Level 16, State 1, Line 1<\/em><\/span><\/p>\n<p><span style=\"color: #ff0000;\"><em>Cannot create index on view &#8216;dbo.IndexedViewExample&#8217; because it contains one or more UNION, INTERSECT, or EXCEPT operators.<\/em><\/span><\/p>\n<p><span style=\"color: #ff0000;\"><em> Consider creating a separate indexed view for each query that is an input to the UNION, INTERSECT, or EXCEPT operators of the original view.<\/em><\/span><\/p>\n<p>If you use <strong>Common Table Expression<\/strong>, you will receive the error as below when creating the index.<\/p>\n<p>Msg 10137, Level 16, State 1, Line 1<\/p>\n<p><span style=\"color: #ff0000;\"><em>Cannot create index on view &#8220;dbo.IndexedViewExample&#8221; because it references common table expression &#8220;TBL_CTE&#8221;. Views referencing common table expressions cannot be indexed. Consider not indexing the view, or removing the common table expression from the view definition.<\/em><\/span><\/p>\n<h2>Condition 5: SET OPTIONS<\/h2>\n<p>You must pay attention to the &#8220;SET Options&#8221; for the views return the same result set as the table. Because different &#8220;SET Options&#8221; may have different results.<\/p>\n<p>For example,<\/p>\n<p>If you type <strong>SET CONCAT_NULL_YIELDS_NULL ON<\/strong> at the beginning of the view, the result will be null when you type &#8216;x&#8217; + null in the select statement.<\/p>\n<p>If you type <strong>SET CONCAT_NULL_YIELDS_NULL OFF<\/strong> at the beginning of the view, the result will be &#8220;x&#8221;.<\/p>\n<p id=\"XBhoxeK\"><img loading=\"lazy\" decoding=\"async\" width=\"506\" height=\"441\" class=\"size-full wp-image-10896 aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/03\/img_5c9745ef41d8d.png\" alt=\"\" \/><\/p>\n<p>You can see the &#8220;SET OPTIONS&#8221; that should be in the table in the below link. In fact, they are default configurations, but if you are using OLE DB or ODBC connection, you need to make some changes. You can see the values that must be and the default values in the following table.<\/p>\n<div style=\"direction: ltr;\">\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/relational-databases\/views\/create-indexed-views?view=sql-server-2017\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/docs.microsoft.com\/en-us\/sql\/relational-databases\/views\/create-indexed-views?view=sql-server-2017<\/a><\/p>\n<h2>Condition 6: Two-part Format<\/h2>\n<p>In the query in the contents of the View, you must write the Select Statements by specifying the schema name as follows. Otherwise, you will receive the following error.<\/p>\n<pre class=\"lang:default decode:true\">schemename.tablename<\/pre>\n<p><em><span style=\"color: #ff0000;\">Msg 4512, Level 16, State 3, Procedure IndexedViewExample, Line 4<\/span><\/em><\/p>\n<p><em><span style=\"color: #ff0000;\">Cannot schema bind view &#8216;dbo.IndexedViewExample&#8217; because name &#8216;MyTable&#8217; is invalid for schema binding. Names must be in two-part format and an object cannot reference itself.<\/span><\/em><\/p>\n<\/div>\n<p>If you use user defined functions within the view, you must also write this function by specifying the schema name.<\/p>\n<h2>Condition 7: GROUP BY Clause in Indexed View<\/h2>\n<p>If you use GROUP BY in the query, you must use COUNT_BIG (*) in the SELECT statement and not use HAVING.<\/p>\n<p><strong>For example;<\/strong><\/p>\n<pre class=\"lang:default decode:true \">USE [TestDB]\nGO\nCREATE VIEW [dbo].[IndexedViewExample]\nWITH SCHEMABINDING AS\nSELECT SUM([ID]) SUM_ID,[Name] FROM [dbo].[MyTable]\nGROUP BY [Name]\nGO\n<\/pre>\n<p>If you don&#8217;t use COUNT_BIG (*) when you use Group By when creating the view, you cannot create a unique clustered index. You will receive an error as follows.<\/p>\n<p><span style=\"color: #ff0000;\"><em>Msg 10138, Level 16, State 1, Line 1<\/em><\/span><\/p>\n<p><span style=\"color: #ff0000;\"><em>Cannot create index on view &#8216;TestDB.dbo.IndexedViewExample&#8217; because its select list does not include a proper use of COUNT_BIG.<\/em><\/span><\/p>\n<p><span style=\"color: #ff0000;\"><em>Consider adding COUNT_BIG(*) to select list.<\/em><\/span><\/p>\n<p id=\"kamXGpl\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-10905  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/03\/img_5c97491ed5512.png\" alt=\"\" width=\"745\" height=\"188\" \/><\/p>\n<h3>Correct View Create Script While You are Using Group By Clause:<\/h3>\n<pre class=\"lang:default decode:true \">USE [TestDB]\nGO\nCREATE VIEW [dbo].[IndexedViewExample]\nWITH SCHEMABINDING AS\nSELECT SUM([ID]) SUM_ID,[Name],COUNT_BIG(*) AS [Count] FROM [dbo].[MyTable]\nGROUP BY [Name]\nGO\n<\/pre>\n<p>But, if you try to create Unique Clustered Index on SUM_ID again, you will receive the below error.<\/p>\n<p><span style=\"color: #ff0000;\"><em>Msg 8661, Level 16, State 0, Line 1<\/em><\/span><\/p>\n<p><span style=\"color: #ff0000;\"><em>Cannot create the clustered index &#8220;UIX_IndexedViewExample&#8221; on view &#8220;TestDB.dbo.IndexedViewExample&#8221; because the index key includes columns<\/em><\/span><\/p>\n<p><span style=\"color: #ff0000;\"><em>that are not in the GROUP BY clause. Consider eliminating columns that are not in the GROUP BY clause from the index key.<\/em><\/span><\/p>\n<p id=\"QABaLdM\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-10908  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/03\/img_5c9749daddf00.png\" alt=\"\" width=\"715\" height=\"169\" \/><\/p>\n<p>Therefore, the clustered index column must be in the GROUP BY Clause.<\/p>\n<h2>Condition 8: Defining Alias<\/h2>\n<p>If you do not define the alias after using a function such as SUM in the select statement in the view, you will get an error as follows.<\/p>\n<p><span style=\"color: #ff0000;\"><em>Msg 4511, Level 16, State 1, Procedure IndexedViewExample, Line 4 [Batch Start Line 0]<\/em><\/span><\/p>\n<p><span style=\"color: #ff0000;\"><em>Create View or Function failed because no column name was specified for column 1.<\/em><\/span><\/p>\n<p><strong>Incorrect view creation script:<\/strong> The error in this script is; there is not an alias for SUM (ID).<\/p>\n<p><strong>It should be:<\/strong> SUM(ID) AS SUM_ID<\/p>\n<pre class=\"lang:default decode:true \">CREATE VIEW [dbo].[IndexedViewExample]  \nWITH SCHEMABINDING  \nAS \nSELECT SUM(ID),Name FROM [dbo].[MyTable]\nGROUP BY Name\n<\/pre>\n<p id=\"Jxmayej\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-10911  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/03\/img_5c974abdd9351.png\" alt=\"\" width=\"711\" height=\"263\" \/><\/p>\n\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_10884\" class=\"pvc_stats all  \" data-element-id=\"10884\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/dbtut.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We create Indexed Views by adding indexes to views. For detailed information about the View concept, I would recommend you read my article &#8220;What is View in SQL Server and How to Create a View&#8220;. Views does not store data. When we convert the views to indexed view, they start to store the data. Therefore, &hellip;<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_10884\" class=\"pvc_stats all  \" data-element-id=\"10884\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/dbtut.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":10914,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[3],"tags":[2712,2716,2722,2723,2729,2731,2732,2725,2727,2730,2719,2733,2728,2715,2717,2726,2718,2720,2721,2724,2713,2714,2711],"class_list":["post-10884","post","type-post","status-publish","format-standard","has-post-thumbnail","","category-mssql","tag-alter-table-alter-column-failed-because-one-or-more-objects-access-this-column","tag-cannot-create-index-on-view-because-it-contains-one-or-more-union","tag-cannot-create-index-on-view-because-it-references-common-table-expression","tag-cannot-create-index-on-view-because-it-references-common-table-expression-views-referencing-common-table-expressions-cannot-be-indexed-consider-not-indexing-the-view","tag-cannot-create-index-on-view-because-its-select-list-does-not-include-a-proper-use-of-count_big","tag-cannot-create-index-on-view-because-its-select-list-does-not-include-a-proper-use-of-count_big-consider-adding-count_big-to-select-list","tag-cannot-create-the-clustered-index-on-view-because-the-index-key-includes-columnsthat-are-not-in-the-group-by-clause","tag-cannot-schema-bind-view-because-name-is-invalid-for-schema-binding","tag-cannot-schema-bind-view-because-name-is-invalid-for-schema-binding-names-must-be-in-two-part-format-and-an-object-cannot-reference-itself","tag-consider-adding-count_big-to-select-list","tag-consider-creating-a-separate-indexed-view-for-each-query-that-is-an-input-to-the-union","tag-consider-eliminating-columns-that-are-not-in-the-group-by-clause-from-the-index-key","tag-group-by-clause-in-indexed-view","tag-indexed-view-restrictions","tag-intersect","tag-names-must-be-in-two-part-format-and-an-object-cannot-reference-itself","tag-or-except-operators","tag-or-except-operators-of-the-original-view","tag-or-except-operators-consider-creating-a-separate-indexed-view-for-each-query-that-is-an-input-to-the-union","tag-or-removing-the-common-table-expression-from-the-view-definition","tag-syntax-is-not-allowed-in-schema-bound-objects","tag-the-create-unique-index-statement-terminated-because-a-duplicate-key-was-found-for-the-object-name","tag-the-object-is-dependent-on-column"],"aioseo_notices":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is Indexed View in SQL Server and How To Create an Indexed View - Database Tutorials<\/title>\n<meta name=\"description\" content=\"What is Indexed View in SQL Server and How To Create an Indexed View\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is Indexed View in SQL Server and How To Create an Indexed View - Database Tutorials\" \/>\n<meta property=\"og:description\" content=\"What is Indexed View in SQL Server and How To Create an Indexed View\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/\" \/>\n<meta property=\"og:site_name\" content=\"Database Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2019-03-24T09:19:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-24T19:20:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/03\/Ads\u0131z.png\" \/>\n\t<meta property=\"og:image:width\" content=\"756\" \/>\n\t<meta property=\"og:image:height\" content=\"334\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"dbtut\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"dbtut\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/\"},\"author\":{\"name\":\"dbtut\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/fc047c39e1e53dce28fc4253529ea408\"},\"headline\":\"What is Indexed View in SQL Server and How To Create an Indexed View\",\"datePublished\":\"2019-03-24T09:19:46+00:00\",\"dateModified\":\"2019-03-24T19:20:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/\"},\"wordCount\":1121,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/dbtut.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/03\/Ads\u0131z.png\",\"keywords\":[\"ALTER TABLE ALTER COLUMN failed because one or more objects access this column\",\"Cannot create index on view because it contains one or more UNION\",\"Cannot create index on view because it references common table expression\",\"Cannot create index on view because it references common table expression. Views referencing common table expressions cannot be indexed. Consider not indexing the view\",\"Cannot create index on view because its select list does not include a proper use of COUNT_BIG\",\"Cannot create index on view because its select list does not include a proper use of COUNT_BIG. Consider adding COUNT_BIG(*) to select list.\",\"Cannot create the clustered index on view because the index key includes columnsthat are not in the GROUP BY clause\",\"Cannot schema bind view because name is invalid for schema binding\",\"Cannot schema bind view because name is invalid for schema binding. Names must be in two-part format and an object cannot reference itself.\",\"Consider adding COUNT_BIG(*) to select list\",\"Consider creating a separate indexed view for each query that is an input to the UNION\",\"Consider eliminating columns that are not in the GROUP BY clause from the index key\",\"GROUP BY Clause in Indexed View\",\"Indexed View Restrictions\",\"INTERSECT\",\"Names must be in two-part format and an object cannot reference itself\",\"or EXCEPT operators\",\"or EXCEPT operators of the original view\",\"or EXCEPT operators. Consider creating a separate indexed view for each query that is an input to the UNION\",\"or removing the common table expression from the view definition.\",\"Syntax '*' is not allowed in schema-bound objects\",\"The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name\",\"The object is dependent on column\"],\"articleSection\":[\"MSSQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/\",\"url\":\"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/\",\"name\":\"What is Indexed View in SQL Server and How To Create an Indexed View - Database Tutorials\",\"isPartOf\":{\"@id\":\"https:\/\/dbtut.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/03\/Ads\u0131z.png\",\"datePublished\":\"2019-03-24T09:19:46+00:00\",\"dateModified\":\"2019-03-24T19:20:05+00:00\",\"description\":\"What is Indexed View in SQL Server and How To Create an Indexed View\",\"breadcrumb\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/#primaryimage\",\"url\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/03\/Ads\u0131z.png\",\"contentUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/03\/Ads\u0131z.png\",\"width\":756,\"height\":334},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dbtut.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What is Indexed View in SQL Server and How To Create an Indexed View\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/dbtut.com\/#website\",\"url\":\"https:\/\/dbtut.com\/\",\"name\":\"Database Tutorials\",\"description\":\"MSSQL, Oracle, PostgreSQL, MySQL, MariaDB, DB2, Sybase, Teradata, Big Data, NOSQL, MongoDB, Couchbase, Cassandra, Windows, Linux\",\"publisher\":{\"@id\":\"https:\/\/dbtut.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/dbtut.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/dbtut.com\/#organization\",\"name\":\"dbtut\",\"url\":\"https:\/\/dbtut.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg\",\"contentUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg\",\"width\":223,\"height\":36,\"caption\":\"dbtut\"},\"image\":{\"@id\":\"https:\/\/dbtut.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/fc047c39e1e53dce28fc4253529ea408\",\"name\":\"dbtut\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c322c32021bf651d9e103b183963c479a9c9791ead0715f4348203496c39aa54?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c322c32021bf651d9e103b183963c479a9c9791ead0715f4348203496c39aa54?s=96&d=mm&r=g\",\"caption\":\"dbtut\"},\"description\":\"We are a team with over 10 years of database management and BI experience. Our Expertises: Oracle, SQL Server, PostgreSQL, MySQL, MongoDB, Elasticsearch, Kibana, Grafana.\",\"sameAs\":[\"http:\/\/NurullahCAKIR\"],\"url\":\"https:\/\/dbtut.com\/index.php\/author\/dbtut\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is Indexed View in SQL Server and How To Create an Indexed View - Database Tutorials","description":"What is Indexed View in SQL Server and How To Create an Indexed View","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/","og_locale":"en_US","og_type":"article","og_title":"What is Indexed View in SQL Server and How To Create an Indexed View - Database Tutorials","og_description":"What is Indexed View in SQL Server and How To Create an Indexed View","og_url":"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/","og_site_name":"Database Tutorials","article_published_time":"2019-03-24T09:19:46+00:00","article_modified_time":"2019-03-24T19:20:05+00:00","og_image":[{"width":756,"height":334,"url":"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/03\/Ads\u0131z.png","type":"image\/png"}],"author":"dbtut","twitter_card":"summary_large_image","twitter_misc":{"Written by":"dbtut","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/#article","isPartOf":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/"},"author":{"name":"dbtut","@id":"https:\/\/dbtut.com\/#\/schema\/person\/fc047c39e1e53dce28fc4253529ea408"},"headline":"What is Indexed View in SQL Server and How To Create an Indexed View","datePublished":"2019-03-24T09:19:46+00:00","dateModified":"2019-03-24T19:20:05+00:00","mainEntityOfPage":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/"},"wordCount":1121,"commentCount":0,"publisher":{"@id":"https:\/\/dbtut.com\/#organization"},"image":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/#primaryimage"},"thumbnailUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/03\/Ads\u0131z.png","keywords":["ALTER TABLE ALTER COLUMN failed because one or more objects access this column","Cannot create index on view because it contains one or more UNION","Cannot create index on view because it references common table expression","Cannot create index on view because it references common table expression. Views referencing common table expressions cannot be indexed. Consider not indexing the view","Cannot create index on view because its select list does not include a proper use of COUNT_BIG","Cannot create index on view because its select list does not include a proper use of COUNT_BIG. Consider adding COUNT_BIG(*) to select list.","Cannot create the clustered index on view because the index key includes columnsthat are not in the GROUP BY clause","Cannot schema bind view because name is invalid for schema binding","Cannot schema bind view because name is invalid for schema binding. Names must be in two-part format and an object cannot reference itself.","Consider adding COUNT_BIG(*) to select list","Consider creating a separate indexed view for each query that is an input to the UNION","Consider eliminating columns that are not in the GROUP BY clause from the index key","GROUP BY Clause in Indexed View","Indexed View Restrictions","INTERSECT","Names must be in two-part format and an object cannot reference itself","or EXCEPT operators","or EXCEPT operators of the original view","or EXCEPT operators. Consider creating a separate indexed view for each query that is an input to the UNION","or removing the common table expression from the view definition.","Syntax '*' is not allowed in schema-bound objects","The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name","The object is dependent on column"],"articleSection":["MSSQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/","url":"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/","name":"What is Indexed View in SQL Server and How To Create an Indexed View - Database Tutorials","isPartOf":{"@id":"https:\/\/dbtut.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/#primaryimage"},"image":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/#primaryimage"},"thumbnailUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/03\/Ads\u0131z.png","datePublished":"2019-03-24T09:19:46+00:00","dateModified":"2019-03-24T19:20:05+00:00","description":"What is Indexed View in SQL Server and How To Create an Indexed View","breadcrumb":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/#primaryimage","url":"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/03\/Ads\u0131z.png","contentUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/03\/Ads\u0131z.png","width":756,"height":334},{"@type":"BreadcrumbList","@id":"https:\/\/dbtut.com\/index.php\/2019\/03\/24\/what-is-indexed-view-in-sql-server-and-how-to-create-an-indexed-view\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dbtut.com\/"},{"@type":"ListItem","position":2,"name":"What is Indexed View in SQL Server and How To Create an Indexed View"}]},{"@type":"WebSite","@id":"https:\/\/dbtut.com\/#website","url":"https:\/\/dbtut.com\/","name":"Database Tutorials","description":"MSSQL, Oracle, PostgreSQL, MySQL, MariaDB, DB2, Sybase, Teradata, Big Data, NOSQL, MongoDB, Couchbase, Cassandra, Windows, Linux","publisher":{"@id":"https:\/\/dbtut.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dbtut.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/dbtut.com\/#organization","name":"dbtut","url":"https:\/\/dbtut.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dbtut.com\/#\/schema\/logo\/image\/","url":"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg","contentUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg","width":223,"height":36,"caption":"dbtut"},"image":{"@id":"https:\/\/dbtut.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/dbtut.com\/#\/schema\/person\/fc047c39e1e53dce28fc4253529ea408","name":"dbtut","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dbtut.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c322c32021bf651d9e103b183963c479a9c9791ead0715f4348203496c39aa54?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c322c32021bf651d9e103b183963c479a9c9791ead0715f4348203496c39aa54?s=96&d=mm&r=g","caption":"dbtut"},"description":"We are a team with over 10 years of database management and BI experience. Our Expertises: Oracle, SQL Server, PostgreSQL, MySQL, MongoDB, Elasticsearch, Kibana, Grafana.","sameAs":["http:\/\/NurullahCAKIR"],"url":"https:\/\/dbtut.com\/index.php\/author\/dbtut\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts\/10884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/comments?post=10884"}],"version-history":[{"count":0,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts\/10884\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/media\/10914"}],"wp:attachment":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/media?parent=10884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/categories?post=10884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/tags?post=10884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}