{"id":9421,"date":"2022-05-17T06:56:00","date_gmt":"2022-05-17T04:56:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=9421"},"modified":"2022-08-04T12:52:48","modified_gmt":"2022-08-04T10:52:48","slug":"drop-sql-server-view","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/","title":{"rendered":"Drop a SQL Server View"},"content":{"rendered":"\n<p>How to drop a SQL Server view with a T-SQL query? The DROP VIEW command allows you to simply delete an existing view with a T-SQL script run from SQL Server Management Studio (SSMS).<\/p>\n\n\n\n<p>The script below is an example of how to delete a view in a SQL database. That is, the view is deleted, but not the source tables to which it points. Note that the deletion is irreversible. It is therefore only the structure in T-SQL and not the data that is potentially lost.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-deleting-an-ms-sql-view-with-a-drop-view-script\">Deleting an MS SQL view with a drop view script<\/h2>\n\n\n\n<p>Furthermore, it is true that views do not contain data, as they point to tables. Deleting a SQL Server view does not delete the underlying data, to dump all the data in a table, use a<strong><a href=\"https:\/\/expert-only.com\/en\/t-sql\/empty-sql-server-table-truncate\/\"> T-SQL script with the TRUNCATE TABLE command<\/a><\/strong>.<\/p>\n\n\n\n<p>Indeed, a view is rather a structure with a selection query and potential filters to filter the displayed data.<\/p>\n\n\n\n<p>This T-SQL script therefore uses the DROP VIEW command to remove it completely from the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Database#Database_management_system\" target=\"_blank\" rel=\"noreferrer noopener\">DBMS<\/a>.<\/p>\n\n\n\n<p>To use it, simply run it in an SSMS window connected to the target database.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">DROP VIEW [dbo][V_SALES];\n<\/pre>\n\n\n\n<p><strong>However, regular backups of your databases should be made to preserve the data and the valuable code that runs on it.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Dependencies between views<\/h3>\n\n\n\n<p>If a view calls another view, then it is always possible to use the intermediate view, without error.<\/p>\n\n\n\n<p>To go further on the method and SQL code management, it&#8217;s a good practice to check the dependencies of the view before deleting it. <\/p>\n\n\n\n<p>For example, let&#8217;s consider the first table Sales that is used by the view dbo.SalesByMonth. Let&#8217;s consider now a third object, a second view that display the Sales with a Year-To-Date vision: dbo.SalesByMonthYTD. <\/p>\n\n\n\n<p>If you drop the first view, then the YTD one will not work anymore. So, it is a good practice to do an impact analysis to see the dependencies between objects in a database.<\/p>\n\n\n\n<p>To execute the code below, first <strong><a href=\"https:\/\/expert-only.com\/en\/t-sql\/script-create-view-sql-server\/\">create the sales view<\/a><\/strong> whose code is available in this MS tutorial.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-tutoriels-sql-et-it wp-block-embed-tutoriels-sql-et-it\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"nEoeJ92UcU\"><a href=\"https:\/\/expert-only.com\/en\/t-sql\/script-create-view-sql-server\/\">Script to create a view in SQL Server<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Script to create a view in SQL Server&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/t-sql\/script-create-view-sql-server\/embed\/#?secret=X6xHUJH3Pf#?secret=nEoeJ92UcU\" data-secret=\"nEoeJ92UcU\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>To learn more about SQL Server views, here is a tutorial English on partitioned views. <strong><a href=\"https:\/\/expert-only.com\/en\/t-sql\/create-partitioned-view-sql-server-group-tables\/\">A view with partitions allows you to display data from several source tables in a single query<\/a><\/strong>.<\/p>\n\n\n\n<p>In practice each partition is a table.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-tutoriels-sql-et-it wp-block-embed-tutoriels-sql-et-it\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/expert-only.com\/en\/t-sql\/create-partitioned-view-sql-server-group-tables\/\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>How to drop a SQL Server view with a T-SQL query? The DROP VIEW command allows you to simply delete an existing view with a T-SQL script run from SQL Server Management Studio (SSMS). The script below is an <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/\" title=\"Drop a SQL Server View\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":6139,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[454],"tags":[630],"class_list":{"0":"post-9421","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-t-sql","8":"tag-drop"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.7 (Yoast SEO v26.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Drop a SQL Server View - T-SQL<\/title>\n<meta name=\"description\" content=\"How to drop a SQL Server view? To delete a view from a database, use the drop view followed by the view name in a script executed in SSMS.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Drop a SQL Server View\" \/>\n<meta property=\"og:description\" content=\"How to drop a SQL Server view? To delete a view from a database, use the drop view followed by the view name in a script executed in SSMS.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL and IT Tutorials\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-17T04:56:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-04T10:52:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/idea-93432E0FFA4_1920x1080.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Expert-Only\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@expert_only\" \/>\n<meta name=\"twitter:site\" content=\"@expert_only\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Expert-Only\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/\"},\"author\":{\"name\":\"Expert-Only\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\"},\"headline\":\"Drop a SQL Server View\",\"datePublished\":\"2022-05-17T04:56:00+00:00\",\"dateModified\":\"2022-08-04T10:52:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/\"},\"wordCount\":402,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/idea-93432E0FFA4_1920x1080.jpeg\",\"keywords\":[\"drop\"],\"articleSection\":[\"T-SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/\",\"url\":\"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/\",\"name\":\"Drop a SQL Server View - T-SQL\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/idea-93432E0FFA4_1920x1080.jpeg\",\"datePublished\":\"2022-05-17T04:56:00+00:00\",\"dateModified\":\"2022-08-04T10:52:48+00:00\",\"description\":\"How to drop a SQL Server view? To delete a view from a database, use the drop view followed by the view name in a script executed in SSMS.\",\"breadcrumb\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/#primaryimage\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/idea-93432E0FFA4_1920x1080.jpeg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/idea-93432E0FFA4_1920x1080.jpeg\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"en\",\"item\":\"https:\/\/expert-only.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Drop a SQL Server View\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/expert-only.com\/en\/#website\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"name\":\"SQL and IT Tutorials\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/expert-only.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/expert-only.com\/en\/#organization\",\"name\":\"Expert-Only\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"width\":381,\"height\":174,\"caption\":\"Expert-Only\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\",\"https:\/\/x.com\/expert_only\",\"https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\",\"name\":\"Expert-Only\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"caption\":\"Expert-Only\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Drop a SQL Server View - T-SQL","description":"How to drop a SQL Server view? To delete a view from a database, use the drop view followed by the view name in a script executed in SSMS.","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:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/","og_locale":"en_US","og_type":"article","og_title":"Drop a SQL Server View","og_description":"How to drop a SQL Server view? To delete a view from a database, use the drop view followed by the view name in a script executed in SSMS.","og_url":"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/","og_site_name":"SQL and IT Tutorials","article_publisher":"https:\/\/www.facebook.com\/ExpertOnlyCom\/","article_published_time":"2022-05-17T04:56:00+00:00","article_modified_time":"2022-08-04T10:52:48+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/idea-93432E0FFA4_1920x1080.jpeg","type":"image\/jpeg"}],"author":"Expert-Only","twitter_card":"summary_large_image","twitter_creator":"@expert_only","twitter_site":"@expert_only","twitter_misc":{"Written by":"Expert-Only","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/#article","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/"},"author":{"name":"Expert-Only","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef"},"headline":"Drop a SQL Server View","datePublished":"2022-05-17T04:56:00+00:00","dateModified":"2022-08-04T10:52:48+00:00","mainEntityOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/"},"wordCount":402,"commentCount":0,"publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/idea-93432E0FFA4_1920x1080.jpeg","keywords":["drop"],"articleSection":["T-SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/","url":"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/","name":"Drop a SQL Server View - T-SQL","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/#primaryimage"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/idea-93432E0FFA4_1920x1080.jpeg","datePublished":"2022-05-17T04:56:00+00:00","dateModified":"2022-08-04T10:52:48+00:00","description":"How to drop a SQL Server view? To delete a view from a database, use the drop view followed by the view name in a script executed in SSMS.","breadcrumb":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/#primaryimage","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/idea-93432E0FFA4_1920x1080.jpeg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/idea-93432E0FFA4_1920x1080.jpeg","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/expert-only.com\/en\/t-sql\/drop-sql-server-view\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"en","item":"https:\/\/expert-only.com\/en\/"},{"@type":"ListItem","position":2,"name":"Drop a SQL Server View"}]},{"@type":"WebSite","@id":"https:\/\/expert-only.com\/en\/#website","url":"https:\/\/expert-only.com\/en\/","name":"SQL and IT Tutorials","description":"","publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/expert-only.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/expert-only.com\/en\/#organization","name":"Expert-Only","url":"https:\/\/expert-only.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","width":381,"height":174,"caption":"Expert-Only"},"image":{"@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ExpertOnlyCom\/","https:\/\/x.com\/expert_only","https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA"]},{"@type":"Person","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef","name":"Expert-Only","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","caption":"Expert-Only"}}]}},"_links":{"self":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/9421","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/comments?post=9421"}],"version-history":[{"count":0,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/9421\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/6139"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=9421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=9421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=9421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}