{"id":147,"date":"2023-10-24T09:43:41","date_gmt":"2023-10-24T07:43:41","guid":{"rendered":"http:\/\/130.61.57.200\/?p=147"},"modified":"2023-10-24T09:44:04","modified_gmt":"2023-10-24T07:44:04","slug":"find-partitioned-tables-with-unalligned-indexes","status":"publish","type":"post","link":"http:\/\/130.61.57.200\/index.php\/2023\/10\/24\/find-partitioned-tables-with-unalligned-indexes\/","title":{"rendered":"Find partitioned tables with non aligned indexes"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Use the following statements to find partitioned tables with non aligned indexes. Unaligned indexes forbid partition switch.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT\n ISNULL(db_name(s.database_id),db_name()) AS DBName\n ,OBJECT_SCHEMA_NAME(i.object_id,DB_ID()) AS SchemaName\n ,o.name AS &#091;Object_Name]\n ,i.name AS Index_name\n ,i.Type_Desc AS Type_Desc\n ,ds.name AS DataSpaceName\n ,ds.type_desc AS DataSpaceTypeDesc\n ,s.user_seeks\n ,s.user_scans\n ,s.user_lookups\n ,s.user_updates\n ,s.last_user_seek\n ,s.last_user_update\nFROM sys.objects AS o\nJOIN sys.indexes AS i ON o.object_id = i.object_id\nJOIN sys.data_spaces ds ON ds.data_space_id = i.data_space_id\nLEFT OUTER JOIN sys.dm_db_index_usage_stats AS s ON i.object_id = s.object_id AND i.index_id = s.index_id AND s.database_id = DB_ID()\nWHERE o.type = &#039;u&#039;\nAND i.type IN (1, 2)\nAND o.object_id in\n(\n SELECT a.object_id from\n (SELECT ob.object_id, ds.type_desc from sys.objects ob \n JOIN sys.indexes ind on ind.object_id = ob.object_id \n JOIN sys.data_spaces ds on ds.data_space_id = ind.data_space_id\n GROUP BY ob.object_id, ds.type_desc ) a \n GROUP BY a.object_id \n HAVING COUNT (*) &gt; 1\n )\nORDER BY &#091;Object_Name] DESC;\nGO<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Use the following statements to find partitioned tables with non aligned indexes. Unaligned indexes forbid partition switch.<\/p>\n","protected":false},"author":1,"featured_media":104,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[50],"class_list":["post-147","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mssql","tag-partitions"],"blocksy_meta":[],"_links":{"self":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/comments?post=147"}],"version-history":[{"count":3,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/147\/revisions"}],"predecessor-version":[{"id":150,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/147\/revisions\/150"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/media\/104"}],"wp:attachment":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/media?parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/categories?post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/tags?post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}