为了得到当前的数据库,你可以使用SELECT DATABASE()
-
select database();
以下是语法-
set @anyVariableName = database(); select @anyVariableName; set @anyVariableName2 = concat('drop database ', @yourVariableName); prepare anyVariableName3 from @yourVariableName2; execute yourVariableName3;
让我们执行上述查询以获取当前数据库并删除它-
mysql> set @currentDatabase = database(); mysql> select @currentDatabase; +------------------+ | @currentDatabase | +------------------+ | employeeonboard | +------------------+ 1 row in set (0.00 sec) mysql> set @sqlQuery = concat('drop database ', @currentDatabase); mysql> prepare stmt from @sqlQuery; Statement prepared mysql> execute stmt;
为了检查是否现在的数据库中存在,使用SELECT DATABASE()
-
mysql> select database();
这将产生以下输出-
+------------+ | database() | +------------+ | NULL | +------------+ 1 row in set (0.00 sec)