2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title: SQL Drop View Statement
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## SQL Drop View Statement
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Introduction
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This guide covers the SQL statement for dropping (deleting) one or more view objects. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								A View is an object that presents data from one or more tables.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Note: before deleting or changing data or objects, remember to have a fresh backup.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								We will cover:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  Using SQL to drop a table 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  Using the workbench to drop a view 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								We'll be using MySQL for the demontration. Check the manual for this function in other Database Managers.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-28 12:51:21 +05:30 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								we'll use student table in this tutorial. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```sql
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								select studentID,FullName,sat_score from student;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Result :
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```text
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+------------+---------------------+-----------+
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| studentID  | FullName            | sat_score |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+------------+---------------------+-----------+
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| 1          | Vincent Uvalle      |  400      |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| 2          | Merle Veres         |  800      |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| 3          | Donte Emmons        |  1000     |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| 4          | Demetrius Mccaster  |  1200     |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| 5          | Tim Goudy           |  1400     |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| 6          | Stephan Monfort     |  1600     |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| 7          | Maximo Backstrom    |  1800     |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| 8          | Dean Pickel         |  200      |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+------------+---------------------+-----------+
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								First of all let's create a view.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```sql
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								create view [Failures] AS
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								select studentID, FullName , sat_score
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								from student
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								where sat_score < = 400;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Let's see what Failures view consists of
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```sql
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								select * from [Failures]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Result :
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```text
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+------------+---------------------+-----------+
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| studentID  | FullName            | sat_score |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+------------+---------------------+-----------+
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| 1          | Vincent Uvalle      |  400      |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| 8          | Dean Pickel         |  200      |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+------------+---------------------+-----------+
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Basic Syntax
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```sql
							 
						 
					
						
							
								
									
										
										
										
											2019-06-28 12:51:21 +05:30 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								drop view [IF EXISTS]
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    view_name [, view_name] ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Drop View SQL
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The if exists portion will "trap" errors, should the view not exist.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```sql
							 
						 
					
						
							
								
									
										
										
										
											2019-06-28 12:51:21 +05:30 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								drop view if exists [Failures];
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Result : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```text
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Failures table dropped successfully.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Using the Workbench
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								From the workbench:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								1) Right click on the view to drop
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								2) select drop view from the menu
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								3) Select either either a) run SQL to review the SQL statement to be executed or b) drop new 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*As with all of these SQL things there is MUCH MORE to them than what's in this introductory guide.  I hope this at least gives you enough to get started.  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Please see the manual for your database manager and have fun trying different options yourself.*