- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use the name of the current database to delete it in MySQL?
To get the current database, you can use the SELECT DATABASE() −
select database();
Following is the syntax −
set @anyVariableName = database(); select @anyVariableName; set @anyVariableName2 = concat('drop database ', @yourVariableName); prepare anyVariableName3 from @yourVariableName2; execute yourVariableName3;
Let us execute the above query in order to get current database and delete it −
mysql> set @currentDatabase = database(); Query OK, 0 rows affected (0.00 sec) mysql> select @currentDatabase; +------------------+ | @currentDatabase | +------------------+ | employeeonboard | +------------------+ 1 row in set (0.00 sec) mysql> set @sqlQuery = concat('drop database ', @currentDatabase); Query OK, 0 rows affected (0.00 sec) mysql> prepare stmt from @sqlQuery; Query OK, 0 rows affected (0.04 sec) Statement prepared mysql> execute stmt; Query OK, 0 rows affected (0.56 sec)
In order to check whether the database exists now, use the SELECT DATABASE() −
mysql> select database();
This will produce the following output −
+------------+ | database() | +------------+ | NULL | +------------+ 1 row in set (0.00 sec)
- Related Articles
- Insert current date to the database in MySQL?
- How to delete data in a MySQL database with Java?
- How to use Boto3 to delete a database from AWS Data Catalog?
- How to get all the MySQL triggers and the triggers for only the current database
- How can we delete a MySQL stored function from the database?
- How to display the name of the Current Thread in C#?
- How to get the name of the current executable in C#?
- How to delete everything in a MongoDB database?
- How to alter the database engine of a MySQL database table?
- How to get field name types from a MySQL database?
- How to update the current delimiter in MySQL?
- How to determine the current delimiter in MySQL?
- How to delete a table from MongoDB database?
- How changes, made in the current transaction, can be permanently recorded in MySQL database?
- How can we change the default MySQL database to the given database?

Advertisements