2

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';

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

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

1 Answer 1

3

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.