MariaDB is an open-source relational database management system that is based on SQL(Structured query language). It is an improved version of MySQL and has various features, security, and performance when compared to MySQL. This database is open source with a strong community that can be trusted in the long run.
In this article, We will learn about the Drop View with syntax along with some examples and so on. After reading this article you will have much knowledge about the Drop View.
Drop View in MariaDB
MariaDB allows us to Create a view which is like creating a virtual table of regularly queried output. It helps to save time in querying the same output and we can also use the view for other queries. If we want to delete any view in MariaDB we will use the DROP VIEW command.
The DROP VIEW command lets us remove one or multiple views at the same time but it will only work if the user has the privilege. After the command place the names of the view(s) separated by commas then end it with a doessemicolon. You can also put the IF EXISTS optional parameter checks if the view exists on the database and if we try to delete a view that does not exist then it will raise an error.
Syntax:
DROP VIEW [IF EXISTS] view1, view2,... ;
Example of Dropping Single and Multiple Views
To understand the MariaDB Drop View we need a table on which we will perform some operations and queries. Let's Create the table in below.
Syntax:
The query creates a table students with id, name, age, email and grade attributes.
CREATE TABLE students
(
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
age INT,
email VARCHAR(255),
grade VARCHAR(10)
);
Output:
Created Students DatabaseExplanation: The image displays the attributes of the table students along with various information such as data type, length, allow NULL etc.
Create Views
View 1: The query creates a view students_grade which contain the name and grade attributes.
CREATE VIEW students_grade AS
SELECT name, grade FROM students;
View 2: The query creates a view students_underage which contain the name and age attributes of students under 18.
CREATE VIEW students_underage AS
SELECT name, age FROM students WHERE age < 18;
Output:
Created ViewsExplanation: In the above Query, We have created a two views on the students table named as students_grade and students_underage which is clearly seen in the output image.
Drop Views
To drop the view you use the DROP VIEW command. In the command you can also add IF EXIST command to check if the view exist before dropping to prevent any potential errors. You can drop multiple views at the same time by separating them with commas.
There are two ways to drop the view:
A) Dropping Only One View at a Time: The given query check if the views exist and then drops the views. Here to drop both the view we are entering drop statements multiple times.
Query 1:
DROP VIEW IF EXISTS students_grade;
DROP VIEW IF EXISTS students_underage;
B) Dropping Both Views Together: The query check if all the views provided exist then it drops all the provided views at the same time. This method is good to drop more than one view at the same time.
Query 2:
DROP VIEW IF EXISTS students_grade, students_underage;
Output:
Dropped ViewsExplanation:In the first Query we firstly check is their any view called as students_grade and students_underage exist or not. If it exist then we simply dropped these views with the help of DROP VIEW Command. As clearly seen in the example, It signifies that the views called as students_grade and students_underage are dropped.
The second Query also give the same output as first give, We can say that either we can write just like first query or like second Query.
Conclusion
Dropping a view is very easy in MariaDB and is very useful for cleaning the Database or the useless views. You must be careful to delete anything in a Database as it must be dependent to other content of the Database. DROP VIEW statement acts as a eraser for removing unwanted views from the Database. It is used for well-organized and efficient for the data.
Similar Reads
MariaDB Drop Trigger In a database management system(DBMS), triggers are essential for automating actions based on specific events. However, there are times when certain triggers need to be removed or dropped from the database. In MariaDB, the DROP TRIGGER statement provides a straightforward way to achieve this task. I
4 min read
Drop Table in MariaDB MariaDB is one of the most widely used open-source relational database management systems, it offers many useful commands for manipulating database structures. It supports the same features that MySQL does but with additional features. Some of the most significant features are new storage engines, J
4 min read
MySQL - Drop View MySQL is a powerful open-source relational database management system that is widely used for building scalable and high-performance databases. Developed by MySQL AB, which is currently owned by Oracle Corporation, MySQL has been around since 1995. It is known for its robust, easy-to-use, and reliab
5 min read
SQLite DROP VIEW SQLite is an embedded database that doesn't use a database like Oracle in the background to operate. It is written in C language and is used by developers who embed a lightweight database over the existing application, browser, or embedded systems. The main features of SQLite are that it is a tiny,
4 min read
SQL - DROP View SQL Views provide a powerful way to simplify complex queries and present data in a more understandable format. However, there may be times when we need to remove a view from our database schema. In SQL, deleting a view is straightforward using the DROP VIEW command. In this article, we will explain
5 min read