{"id":827,"date":"2009-06-16T12:30:00","date_gmt":"2009-06-16T12:30:00","guid":{"rendered":"\/blogs\/paul\/post\/Misconceptions-about-running-DMVs-on-database-with-lower-compatibility-levels.aspx"},"modified":"2009-06-16T12:30:00","modified_gmt":"2009-06-16T12:30:00","slug":"misconceptions-about-running-dmvs-on-databases-with-lower-compatibility-levels","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-about-running-dmvs-on-databases-with-lower-compatibility-levels\/","title":{"rendered":"Misconceptions about running DMVs on databases with lower compatibility levels"},"content":{"rendered":"<p>\n<font face=\"verdana,geneva\" size=\"2\">It&#39;s lunchtime for my class &#8211; time for a blog post! This is an interesting one that crops up every so often (just an hour ago on SQL Server Central) and is not known very widely at all.<\/font>\n<\/p>\n<p>\n<font face=\"verdana,geneva\" size=\"2\">There&#39;s a misconception that you cannot run DMVs in databases that have compatibility levels of 80 or less. It&#39;s not true.<\/font>\n<\/p>\n<p>\n<font face=\"verdana,geneva\" size=\"2\">Here&#39;s an example:<\/font>\n<\/p>\n<blockquote>\n<p>\n\t<font face=\"courier new,courier\" size=\"2\">USE master;<br \/>\n\tGO<br \/>\n\tEXEC sp_dbcmptlevel AdventureWorks, 80;<\/font>\n\t<\/p>\n<p>\n\t<font face=\"courier new,courier\" size=\"2\">USE AdventureWorks;<br \/>\n\tGO<\/font>\n\t<\/p>\n<p>\n\t<font face=\"courier new,courier\" size=\"2\">SELECT [object_id], [index_id]<br \/>\n\tFROM sys.dm_db_index_physical_stats (<br \/>\n\t&nbsp;&nbsp;&nbsp; DB_ID (&#39;AdventureWorks&#39;), NULL, NULL, NULL, NULL)<br \/>\n\tWHERE [avg_fragmentation_in_percent] &gt; 30;<br \/>\n\tGO<\/font>\n\t<\/p>\n<\/blockquote>\n<p>\n<font face=\"verdana,geneva\" size=\"2\">You get the incredibly useful and explanatory message:<\/font>\n<\/p>\n<blockquote>\n<p>\n\t<font face=\"courier new,courier\" size=\"2\">Msg 102, Level 15, State 1, Line 2<br \/>\n\tIncorrect syntax near &#39;(&#39;.<\/font>\n\t<\/p>\n<\/blockquote>\n<p>\n<font face=\"verdana,geneva\" size=\"2\">What the heck does that mean? It really means that the query processor refused to recognize the DMV name because the database is running in 80 or lower compatibility level.<\/font>\n<\/p>\n<p>\n<font face=\"verdana,geneva\" size=\"2\">Here&#39;s the trick &#8211; execute the DMV in the context of database that&#39;s in 90 compatibility level or higher, and it will let you do it &#8211; even if you&#39;re actually targeting a database in a lower compatibility level.<\/font>\n<\/p>\n<blockquote>\n<p>\n\t<font face=\"courier new,courier\" size=\"2\">USE master;<br \/>\n\tGO<\/p>\n<p>\tSELECT [object_id], [index_id]<br \/>\n\tFROM sys.dm_db_index_physical_stats (<br \/>\n\t&nbsp;&nbsp;&nbsp; DB_ID (<strong><u>&#39;AdventureWorks&#39;<\/u><\/strong>), NULL, NULL, NULL, NULL)<br \/>\n\tWHERE [avg_fragmentation_in_percent] &gt; 30;<br \/>\n\tGO<\/font>\n\t<\/p>\n<p>\n\t<font face=\"courier new,courier\" size=\"2\">object_id&nbsp;&nbsp; index_id<br \/>\n\t&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8211;<br \/>\n\t18099105&nbsp;&nbsp;&nbsp; 2<br \/>\n\t30623152&nbsp;&nbsp;&nbsp; 2<br \/>\n\t30623152&nbsp;&nbsp;&nbsp; 3<br \/>\n\t30623152&nbsp;&nbsp;&nbsp; 4<br \/>\n\t66099276&nbsp;&nbsp;&nbsp; 1<br \/>\n\t66099276&nbsp;&nbsp;&nbsp; 2<\/font>\n\t<\/p>\n<p>\n\t<font face=\"courier new,courier\" size=\"2\">&#8230;<\/font>\n\t<\/p>\n<\/blockquote>\n<p>\n<font face=\"verdana,geneva\" size=\"2\">Note that I executed the DMV from the context of <font face=\"courier new,courier\">master<\/font>, but targeted <font face=\"courier new,courier\">AdventureWorks<\/font>, which is in the 80 compatibility level.&nbsp;<\/font>\n<\/p>\n<p>\n<font face=\"verdana,geneva\" size=\"2\">Have fun!<\/font><\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#39;s lunchtime for my class &#8211; time for a blog post! This is an interesting one that crops up every so often (just an hour ago on SQL Server Central) and is not known very widely at all. There&#39;s a misconception that you cannot run DMVs in databases that have compatibility levels of 80 or [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61,95],"tags":[],"class_list":["post-827","post","type-post","status-publish","format-standard","hentry","category-misconceptions","category-tools"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Misconceptions about running DMVs on databases with lower compatibility levels - Paul S. Randal<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-about-running-dmvs-on-databases-with-lower-compatibility-levels\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Misconceptions about running DMVs on databases with lower compatibility levels - Paul S. Randal\" \/>\n<meta property=\"og:description\" content=\"It&#039;s lunchtime for my class &#8211; time for a blog post! This is an interesting one that crops up every so often (just an hour ago on SQL Server Central) and is not known very widely at all. There&#039;s a misconception that you cannot run DMVs in databases that have compatibility levels of 80 or [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-about-running-dmvs-on-databases-with-lower-compatibility-levels\/\" \/>\n<meta property=\"og:site_name\" content=\"Paul S. Randal\" \/>\n<meta property=\"article:published_time\" content=\"2009-06-16T12:30:00+00:00\" \/>\n<meta name=\"author\" content=\"Paul Randal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Paul Randal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-about-running-dmvs-on-databases-with-lower-compatibility-levels\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-about-running-dmvs-on-databases-with-lower-compatibility-levels\/\",\"name\":\"Misconceptions about running DMVs on databases with lower compatibility levels - Paul S. Randal\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\"},\"datePublished\":\"2009-06-16T12:30:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-about-running-dmvs-on-databases-with-lower-compatibility-levels\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-about-running-dmvs-on-databases-with-lower-compatibility-levels\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-about-running-dmvs-on-databases-with-lower-compatibility-levels\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Misconceptions about running DMVs on databases with lower compatibility levels\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\",\"name\":\"Paul S. Randal\",\"description\":\"In Recovery...\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\",\"name\":\"Paul Randal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g\",\"caption\":\"Paul Randal\"},\"sameAs\":[\"http:\/\/3.209.169.194\/blogs\/paul\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/author\/paul\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Misconceptions about running DMVs on databases with lower compatibility levels - Paul S. Randal","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:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-about-running-dmvs-on-databases-with-lower-compatibility-levels\/","og_locale":"en_US","og_type":"article","og_title":"Misconceptions about running DMVs on databases with lower compatibility levels - Paul S. Randal","og_description":"It&#39;s lunchtime for my class &#8211; time for a blog post! This is an interesting one that crops up every so often (just an hour ago on SQL Server Central) and is not known very widely at all. There&#39;s a misconception that you cannot run DMVs in databases that have compatibility levels of 80 or [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-about-running-dmvs-on-databases-with-lower-compatibility-levels\/","og_site_name":"Paul S. Randal","article_published_time":"2009-06-16T12:30:00+00:00","author":"Paul Randal","twitter_misc":{"Written by":"Paul Randal","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-about-running-dmvs-on-databases-with-lower-compatibility-levels\/","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-about-running-dmvs-on-databases-with-lower-compatibility-levels\/","name":"Misconceptions about running DMVs on databases with lower compatibility levels - Paul S. Randal","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website"},"datePublished":"2009-06-16T12:30:00+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-about-running-dmvs-on-databases-with-lower-compatibility-levels\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-about-running-dmvs-on-databases-with-lower-compatibility-levels\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-about-running-dmvs-on-databases-with-lower-compatibility-levels\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/paul\/"},{"@type":"ListItem","position":2,"name":"Misconceptions about running DMVs on databases with lower compatibility levels"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/","name":"Paul S. Randal","description":"In Recovery...","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/paul\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce","name":"Paul Randal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g","caption":"Paul Randal"},"sameAs":["http:\/\/3.209.169.194\/blogs\/paul"],"url":"https:\/\/www.sqlskills.com\/blogs\/paul\/author\/paul\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/comments?post=827"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/827\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/media?parent=827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/categories?post=827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/tags?post=827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}