Open In App

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, JSON API support, and parallel data replication.

One such command that performs an important role in database administration is the DROP TABLE command. In this article, We will discuss the DROP TABLE command in MariaDB along with syntax, table creation, and examples of dropping the table using multiple methods.



DROP TABLE in MariaDB

MariaDB’s DROP TABLE command is designed to delete a current table as well as all the data and objects related to it. The main scenarios for the use of DROP TABLE are the removal of outdated tables, reforming database structures, or starting from scratch when required. With the help of DROP TABLE, the data can be deleted permanently.

Syntax:



DROP TABLE [IF EXISTS] table_name;

Explanation:

Syntax to drop Multiple Tables:

DROP TABLE [IS EXISTS] table1, table2, table3,...;

Explanation: In this syntax, you specify a comma list of tables you want to remove after the drop table keywords.

Examples of DROP TABLE

For good understanding of the DROP TABLE Command, Let’s create an table through which we will understand the DROP TABLE Command better and get the deep understanding of DROP TABLE Command.

Employees Table

CREATE TABLE Employees 
(
emp_id int,
emp_name varchar(255) not null
);

Products Table

CREATE TABLE Products 
(
pro_name varchar(255),
price decimal(10,2)
);

States Table

CREATE TABLE States
(
id int,
state_name varchar(255),
area decimal (15,2)
);

Verify whether the table is created successfully or not executing the below command.

Query:

SHOW TABLES;

You can see below our tables got created successfully.

Output:

Tables

Explanation: As we can see in the output that we have all tables which we ill created above.

Drop One Table

Let’s look at a simple DROP TABLE example that shows how to use the DROP TABLE statement to drop one table in MariaDB.

Query:

DROP TABLE employees;

Check using SHOW TBALES command.

Output:

Drop table

Explanation: : As we can see in the output that now no table named as employees is there in database.

Drop Multiple Table

Let’s look at an example where we want to drop more than one table using the DROP TABLE statement.

Query:

DROP TABLE Products, States;

Output:

Drop All Tables

Explnation: As we can see in the output that now no table named as product and states in database.

Drop table Using Management Studio

We can drop table using management studio also.

First create a new table called Books:

CREATE TABLE Books 
(
id int,
bookName varchar(255)
);

Step 1: Select the table that we want to delete and then right click on that. We will see a page like this:

Drop Table

Step 2: Click on drop and then it will generate a pop up and click ok.

Drop Table

Step 3: We can verify that the table is deleted or not.

SHOW TABLES;

No Tables in database

Precautions and Considerations

Conclusion

Overall, the DROP TABLE command in MariaDB is a powerful tool for database structure management, but it has great responsibilities associated with it. This command must be used by database administrators with caution, best practices, and consequences. Effective risk mitigation steps related to the DROP TABLE include performing regular backups, using IF EXISTS, and understanding dependencies. With proper planning and following these pointers, administrators can exploit the potential of DROP TABLE in their MariaDB environments.


Article Tags :