Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I would like to dynamically use a database inside a stored procedure but the use database_name command is not supported inside procedures.

What alternatives are there?

share|improve this question

1 Answer 1

From MySQL Documentation on Stored Routine Syntax When the routine is invoked, an implicit USE db_name is performed (and undone when the routine terminates). USE statements within stored routines are not permitted

If you need to query tables from other databases you can do it like DBName.TableName. and you can change DBName dynamically.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.