Reputation: 145
I try to assign "DATABASE()" which returns the name of the current database to a variable "@mydb" and to use it back to drop this database.
SET @mydb = DATABASE();
DROP DATABASE @mydb;
And i got this error ER_PARSE_ERROR near @mydb
Upvotes: 0
Views: 78
Reputation: 49385
As P.Salmon mentioned you have to use Prepared Statements:
SET @mydb = DATABASE();
SET @sql = CONCAT('DROP DATABASE ', @mydb);
PREPARE stmt1 FROM @sql;
EXECUTE stmt1;
Upvotes: 1