开发者

MySQL User-Defined Variable Values Can't be Used as Identifiers. How do I do this?

According to the manual:

User variables... cannot be used directly in an SQL statement as an identifier or as part of an identifier, such as in contexts where a table or database name is expected

Which explains why what I've been trying doesn't work:

set @databaseName := 'job_hunt_2'开发者_JS百科;

drop database @databaseName;
create database @databaseName;
use @databaseName;

Is there a way to accomplish this, or is it simply impossible? Thanks!


may be you should try following approach:

set @databaseName := 'job_hunt_2';
SET @s = CONCAT('drop database ', @databaseName); 
PREPARE stmt1 FROM @s; 
EXECUTE stmt1; 
DEALLOCATE PREPARE stmt1;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜