{"id":18393,"date":"2022-11-07T06:25:00","date_gmt":"2022-11-07T05:25:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=18393"},"modified":"2022-11-22T10:23:28","modified_gmt":"2022-11-22T09:23:28","slug":"test-and-drop-a-sql-server-view-if-exists","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/","title":{"rendered":"Test and drop a SQL Server view if it exists in the database"},"content":{"rendered":"\n<h4 class=\"has-text-align-center wp-block-heading\" id=\"h-how-to-test-and-then-drop-a-sql-server-view-if-it-exists-in-the-database\"><strong><em>How to test and then drop a SQL Server view, if it exists in the database?<\/em><\/strong><\/h4>\n\n\n\n<p>Here is how to test the existence and drop a SQL Server view with a T-SQL script. Use this script as an example to test the existence of the view before deleting it. The goal is to not generate an error during the execution of a deployment script for example. And thus, not to execute a script on a object not in the database, or renamed for example.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#1-drop-a-sql-server-view-if-it-exists-with-all-versions\" >1. Drop a SQL Server view if it exists with all versions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#2-drop-a-view-with-the-ms-sql-version-2016-and-older\" >2. Drop a view with the MS SQL version 2016 and older<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#3-drop-all-the-views-from-a-ms-sql-database\" >3. Drop all the views from a MS SQL database<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1-drop-a-sql-server-view-if-it-exists-with-all-versions\"><\/span>1. Drop a SQL Server view if it exists with all versions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Indeed, deleting a non-existent view returns this error in SQL Server Management Studio (SSMS).<\/p>\n\n\n\n<p><em>Cannot drop the view &#8216;dbo.V_SALES&#8217;, because it does not exist or you do not have permission.<\/em><\/p>\n\n\n\n<p>Or the same error message in French:<\/p>\n\n\n\n<p><em>Msg 3701: The view does not exist or you do not have permission.<\/em><\/p>\n\n\n\n<p>Here is the solution, use the SQL Server IF EXISTS function to test the existence of the view before deleting it, as in this example.<\/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=\"\">IF EXISTS ( \n  SELECT 1 \n  FROM sys.objects \n  WHERE object_id = object_id(N'[dbo].[V_SALES]') \n  AND type in (N'V') \n) \nBEGIN DROP VIEW [dbo].[V_SALES]; \nEND;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2-drop-a-view-with-the-ms-sql-version-2016-and-older\"><\/span>2. Drop a view with the MS SQL version 2016 and older<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Shorter script with only one line of code, the DROP VIEW IF EXISTS function, which is available since the SQL Server 2016 version.<\/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=\"\">IF EXISTS DROP VIEW [dbo];[V_SALES];\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3-drop-all-the-views-from-a-ms-sql-database\"><\/span>3. Drop all the views from a MS SQL database<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Finally, for this third part on deleting views, here is how to create a dynamic script with a loop to filter and delete all views with a particular prefix or suffix. This multi-part code automates these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create the variables<\/li>\n\n\n\n<li>Instantiate the variables<\/li>\n\n\n\n<li>Create a slider to select the name of the views with a filter on the name<\/li>\n\n\n\n<li>Browse the slider<\/li>\n\n\n\n<li>For each row in the cursor, build and display a query to delete the view<\/li>\n\n\n\n<li>Close and delete the cursor reference.<\/li>\n<\/ol>\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=\"\">DECLARE\n  @View_Name AS NVARCHAR(50),\n  @Drop_SQL_Query AS NVARCHAR(100),\n  @Drop_SQL_Query_Full AS NVARCHAR(200);\n\nSET @Drop_SQL_Query = 'IF EXISTS DROP VIEW ';\n\nDECLARE View_Name_Cursor CURSOR   FOR \n  SELECT [Name] \n  FROM SYS.VIEWS\n  WHERE [Name] LIKE '%_SALES_%'\n  ORDER BY [Name];\n\nOPEN View_Name_Cursor;\nFETCH NEXT FROM View_Name_Cursor into @View_Name;\n\nWHILE @@FETCH_STATUS = 0  \nBEGIN \n  SET @Drop_SQL_Query_Full = @Drop_SQL_Query + @View_Name;\n  PRINT @Drop_SQL_Query_Full;\n  --EXEC @Drop_SQL_Query_Full;\n  FETCH NEXT FROM View_Name_Cursor into @View_Name;\nEND\n\nCLOSE View_Name_Cursor;  \nDEALLOCATE View_Name_Cursor; \n<\/pre>\n\n\n\n<p>Indeed, this script allows you to drop all the views created in a database. It uses a filter, which can be easily modified to select views based on a suffix, a prefix, a filter as in the example above, or simply all views in the database.<\/p>\n\n\n\n<p>This script does not actually drop the MS SQL views, but dynamically generates the commands to drop the views. To run it directly inside the T-SQL code, simply remove the comments on the following line.<\/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=\"\">EXEC sp_executesql @Drop_SQL_Query_Full;\n<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"740\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/sq-server-generate-script-to-drop-all-views-from-db-1.jpg\" alt=\"Test and Drop a SQL Server view if it exists - drop all the view in a SQL database\" class=\"wp-image-18383\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/sq-server-generate-script-to-drop-all-views-from-db-1.jpg 720w, https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/sq-server-generate-script-to-drop-all-views-from-db-1-292x300.jpg 292w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><figcaption class=\"wp-element-caption\">Drop all SQL Server views from a database with a script<\/figcaption><\/figure>\n\n\n\n<p>These are Data Definition Language (<a href=\"https:\/\/cloud.google.com\/bigquery\/docs\/reference\/standard-sql\/data-definition-language\" target=\"_blank\" rel=\"noreferrer noopener\">DDL<\/a>) queries. This more general page on views shows some examples of the <a href=\"https:\/\/expert-only.com\/en\/manage-sql-server-views-with-t-sql-code\/\">main DDL commands for managing views with T-SQL scripts<\/a>. To conclude, this tutorial explains how to test and drop a SQL Server view with versions before SQL Server 2016, and after in one line. Then presents a dynamic script to delete all views in a SQL database.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"eUM1xdYMPb\"><a href=\"https:\/\/expert-only.com\/en\/manage-sql-server-views-with-t-sql-code\/\">Manage SQL Server views with T-SQL code<\/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;Manage SQL Server views with T-SQL code&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/manage-sql-server-views-with-t-sql-code\/embed\/#?secret=WpS9a1FcL1#?secret=eUM1xdYMPb\" data-secret=\"eUM1xdYMPb\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>How to test and then drop a SQL Server view, if it exists in the database? Here is how to test the existence and drop a SQL Server view with a T-SQL script. Use this script as an example <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/\" title=\"Test and drop a SQL Server view if it exists in the database\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":6274,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[454],"tags":[],"class_list":{"0":"post-18393","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-t-sql"},"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>Test and drop a SQL Server view if it exists in the database - T-SQL<\/title>\n<meta name=\"description\" content=\"How to test and drop a SQL Server view, only if it exists in the database? Use scripts to test and also to drop all views in a database.\" \/>\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\/test-and-drop-a-sql-server-view-if-exists\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Test and drop a SQL Server view if it exists in the database\" \/>\n<meta property=\"og:description\" content=\"How to test and drop a SQL Server view, only if it exists in the database? Use scripts to test and also to drop all views in a database.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/\" \/>\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-11-07T05:25:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-22T09:23:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/city-4F3310F581A_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=\"4 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\/test-and-drop-a-sql-server-view-if-exists\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/\"},\"author\":{\"name\":\"Expert-Only\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\"},\"headline\":\"Test and drop a SQL Server view if it exists in the database\",\"datePublished\":\"2022-11-07T05:25:00+00:00\",\"dateModified\":\"2022-11-22T09:23:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/\"},\"wordCount\":469,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/city-4F3310F581A_1920x1080.jpeg\",\"articleSection\":[\"T-SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/\",\"url\":\"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/\",\"name\":\"Test and drop a SQL Server view if it exists in the database - T-SQL\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/city-4F3310F581A_1920x1080.jpeg\",\"datePublished\":\"2022-11-07T05:25:00+00:00\",\"dateModified\":\"2022-11-22T09:23:28+00:00\",\"description\":\"How to test and drop a SQL Server view, only if it exists in the database? Use scripts to test and also to drop all views in a database.\",\"breadcrumb\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#primaryimage\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/city-4F3310F581A_1920x1080.jpeg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/city-4F3310F581A_1920x1080.jpeg\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"en\",\"item\":\"https:\/\/expert-only.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Test and drop a SQL Server view if it exists in the database\"}]},{\"@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":"Test and drop a SQL Server view if it exists in the database - T-SQL","description":"How to test and drop a SQL Server view, only if it exists in the database? Use scripts to test and also to drop all views in a database.","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\/test-and-drop-a-sql-server-view-if-exists\/","og_locale":"en_US","og_type":"article","og_title":"Test and drop a SQL Server view if it exists in the database","og_description":"How to test and drop a SQL Server view, only if it exists in the database? Use scripts to test and also to drop all views in a database.","og_url":"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/","og_site_name":"SQL and IT Tutorials","article_publisher":"https:\/\/www.facebook.com\/ExpertOnlyCom\/","article_published_time":"2022-11-07T05:25:00+00:00","article_modified_time":"2022-11-22T09:23:28+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/city-4F3310F581A_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":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#article","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/"},"author":{"name":"Expert-Only","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef"},"headline":"Test and drop a SQL Server view if it exists in the database","datePublished":"2022-11-07T05:25:00+00:00","dateModified":"2022-11-22T09:23:28+00:00","mainEntityOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/"},"wordCount":469,"commentCount":0,"publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/city-4F3310F581A_1920x1080.jpeg","articleSection":["T-SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/","url":"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/","name":"Test and drop a SQL Server view if it exists in the database - T-SQL","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#primaryimage"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/city-4F3310F581A_1920x1080.jpeg","datePublished":"2022-11-07T05:25:00+00:00","dateModified":"2022-11-22T09:23:28+00:00","description":"How to test and drop a SQL Server view, only if it exists in the database? Use scripts to test and also to drop all views in a database.","breadcrumb":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#primaryimage","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/city-4F3310F581A_1920x1080.jpeg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2018\/06\/city-4F3310F581A_1920x1080.jpeg","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/expert-only.com\/en\/t-sql\/test-and-drop-a-sql-server-view-if-exists\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"en","item":"https:\/\/expert-only.com\/en\/"},{"@type":"ListItem","position":2,"name":"Test and drop a SQL Server view if it exists in the database"}]},{"@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\/18393","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=18393"}],"version-history":[{"count":0,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/18393\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/6274"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=18393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=18393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=18393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}