

In this case, MySQL will terminate the statement without issuing any error. You can bypass the error by using IF EXISTS after the DROP DATABASE keywords. If you try to drop a database that does not exist, MySQL will show an error. In this statement, you specify the name of the database which you want to delete after the DROP DATABASE keywords. The following shows the syntax of the DROP DATABASE statement: DROP DATABASE database_name

Therefore, you need to be very careful while using this statement. This will delete all the tables and other objects from that database. The DROP DATABASE statement allows us to drop a database from the MySQL server permanently. You can drop/delete/remove a database from MySQL mainly in two ways:ĭropping a MySQL database using Command Line Client Therefore, you need to be very careful with this command as this will remove all the data available in the database. This command will remove the database along with all the tables, indexes, and constraints permanently. The DROP DATABASE statement is used to drop/delete/remove a database from the MySQL server.
MYSQL DROP DATABASE HOW TO
If a permanent table exists with the same name as the temporary table, MySQL will not delete the permanent table.Summary: in this tutorial, you will learn how to drop/delete/remove a database from the MySQL server using the MySQL DROP DATABASE command. Please note that the above statement will delete only the temporary table. The above statement deletes the Student_marks table from MySQL. To drop a temporary table, you use the following syntax. Total_marks DECIMAL(10,2) NOT NULL DEFAULT 0.00, Let us now check the DROP TABLE statement for the temporary table. DROP TABLE courses, enrolls 3) Dropping Temporary Table To delete multiple tables in a single statement, you use the following statement. Table: enrolls mysql> SELECT * FROM enrolls Table: courses mysql> SELECT * FROM courses Suppose, we have two tables named courses and enrolls as follows: In this example, we will check how to drop multiple tables using a single DROP TABLE statement. However, if we use the IF EXISTS keywords before mentioning the table_name in the DROP TABLE statement, MySQL does not issue any error. If we try to drop a table that does not exist then MySQL issue an error as below. The above statement removes the Products table permanently from the database. To drop this Products table, you use the following statement. Suppose we have a table named Products in the mysqltutorial database as below. In this example, we will check an example of dropping a single table from the MySQL database. Let us check the different options of the MySQL DROP TABLE command using a few examples.

table_name – the name of the table that you need to drop.Here is the more generic syntax of the drop table command. Mysql> DROP TABLE schema_name.table_name The following are the syntax of dropping a table from MySQL. So, we need to be very careful before executing this command as the wrong table name provided to the statement can lead to the loss of data.

This statement deletes the table structure along with the data completely from MySQL. MySQL allows us to drop a table from the database using the MySQL DROP TABLE statement. Summary: in this tutorial, you will learn how to drop a table using the MySQL DROP TABLE statement with syntax and examples.
