{"id":118,"date":"2017-10-24T00:08:18","date_gmt":"2017-10-24T00:08:18","guid":{"rendered":"http:\/\/eipsoftware.com\/musings\/?p=118"},"modified":"2018-02-19T16:40:09","modified_gmt":"2018-02-19T16:40:09","slug":"all-views","status":"publish","type":"post","link":"https:\/\/eipsoftware.com\/musings\/all-views\/","title":{"rendered":"Views, we need all the Views"},"content":{"rendered":"<p>There are times when you want to find all of the views that are in your Microsoft SQL database.\u00a0 Especially when there are 1,000&#8217;s of views.\u00a0 Each with the naming convention of the previous 5 DBA&#8217;s personal whims.\u00a0 Normally as a database ages the views will become duplicative and add to the general clutter that gets in the way of efficiency.<\/p>\n<h4>List all views in a database<\/h4>\n<p><!--more-->Below is the query that will list all of the view in the database.<\/p>\n<pre class=\"theme:github font:courier-new width:700 lang:tsql decode:true\">-- ---------------------------------------------------------------------------\r\n-- List all views for a database\r\n-- ---------------------------------------------------------------------------\r\nSELECT\t\tSCHEMA_NAME(schema_id) AS schema_name\r\n\t\t\t,name AS view_name\r\n\t\t\t,OBJECTPROPERTYEX(OBJECT_ID,'IsIndexed') AS IsIndexed\r\n\t\t\t,OBJECTPROPERTYEX(OBJECT_ID,'IsIndexable') AS IsIndexable\r\n\t\t\t--,*\r\nFROM\t\tsys.views;<\/pre>\n<p>&nbsp;<\/p>\n<h4>Explanation<\/h4>\n<p>The query will run against the system table sys.views.\u00a0 The query returns the schema name, view name and if the view has columns that are indexed or indexable.<\/p>\n<h4>Caveat<\/h4>\n<p>You will need elevated privileges to system access to run a query against the system tables.\u00a0 You only need elevated privileges for the database you want to query.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are times when you want to find all of the views that are in your Microsoft SQL database.\u00a0 Especially when there are 1,000&#8217;s of views.\u00a0 Each with the naming convention of the previous 5 DBA&#8217;s personal whims.\u00a0 Normally as a database ages the views will become duplicative and add to the general clutter that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[43,4,6],"tags":[13,14,15,26],"series":[],"class_list":["post-118","post","type-post","status-publish","format-standard","hentry","category-sql-t-sql","category-code","category-sql","tag-hint","tag-sql","tag-t-sql","tag-views"],"_links":{"self":[{"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/posts\/118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/comments?post=118"}],"version-history":[{"count":4,"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/posts\/118\/revisions"}],"predecessor-version":[{"id":147,"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/posts\/118\/revisions\/147"}],"wp:attachment":[{"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/media?parent=118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/categories?post=118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/tags?post=118"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/series?post=118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}