USE and DO
USE selects the default database; DO evaluates expressions and discards the result.
Syntax#
USE db_name
DO expr [, expr] ...Arguments#
| Name | Meaning | Default |
|---|---|---|
db_name | The database that unqualified table names refer to. information_schema is allowed. | none |
expr | Any expression, including user-variable assignment @x := value. | none |
Remarks#
USEof a database that does not exist is error 1049; one the account has no privilege on is error 1044.USE information_schemais always allowed.- Without a
USE(or a database named at connection), a statement with an unqualified table name is error 1046No database selected. - A routine runs with its own database as the default while it runs; the caller's is restored.
DOevaluates the expressions and returns nothing (an OK packet). It is used for side effects:DO SLEEP(0),DO @y := 9,DO NEXTVAL(s).
Examples#
Example:
USE qf1;
DO 1 + 1, SLEEP(0);
DO @y := 9;
SELECT @y;