Languages
[Edit]
EN

MySQL - Drop view

0 points
Created by:
Teilsa
1255

In this article, we would like to show you how to DROP VIEW in MySQL.

Quick solution:

DROP VIEW `view_name`;

Practical example

To show how the DROP VIEW statement works, we will use the following table:

MySQL - example data used with DROP VIEW statement
MySQL - example data used with DROP VIEW statement

Note:

At the end of this article you can find database preparation SQL queries.

Example 

In this example, we will delete the Spain Users view which we created in this article.

Query:

DROP VIEW `Spain Users`;

Output:

MySQL - DROP VIEW result in HeidiSQL (before)
MySQL - DROP VIEW result in HeidiSQL (before)
MySQL - DROP VIEW IF EXISTS result in HeidiSQL (after)
MySQL - DROP VIEW IF EXISTS result in HeidiSQL (after)

Popular error

If you try to drop a view that already exists with DROP VIEW query you will get an error:

MySQL - SQL Error: Unknown VIEW 'view_name'
MySQL - SQL Error: Unknown VIEW 'view_name'

If you try to DROP VIEW IF EXISTS you will get a warning instead:

MySQL - Note: Unknown VIEW 'view_name'
MySQL - Note: Unknown VIEW 'view_name'

Note:

For more information go to this article: MySQL - Drop view if exists

Database preparation

create_tables.sql file:

CREATE TABLE `users` (
	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`name` VARCHAR(100) NOT NULL,
	`email` VARCHAR(100) NOT NULL,
	`country` VARCHAR(15) NOT NULL,
	PRIMARY KEY (`id`)
)
ENGINE=InnoDB;

insert_data.sql file:

INSERT INTO `users`
	(`name`, `email`, `country`)
VALUES
	('Tom', 'tom01@email.com', 'Poland'),
	('Chris','chris123@email.com', 'Spain'),
	('Jack','jack32@email.com', 'Spain'),
   ('Kim','kim103@email.com', 'Vietnam'),
   ('Marco','marco942@email.com', 'Italy'),
	('Kate','kate227@email.com', 'Spain'),
	('Nam','nam393@email.com', 'Vietnam');

Related posts

Alternative titles

  1. MySQL - delete view
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - Drop view

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join