SQL reference (MySQL and MariaDB dialects)

USE and DO

USE selects the default database; DO evaluates expressions and discards the result.

Syntax#

SQL
USE db_name

DO expr [, expr] ...

Arguments#

NameMeaningDefault
db_nameThe database that unqualified table names refer to. information_schema is allowed.none
exprAny expression, including user-variable assignment @x := value.none

Remarks#

  • USE of a database that does not exist is error 1049; one the account has no privilege on is error 1044. USE information_schema is always allowed.
  • Without a USE (or a database named at connection), a statement with an unqualified table name is error 1046 No database selected.
  • A routine runs with its own database as the default while it runs; the caller's is restored.
  • DO evaluates 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:

SQL
USE qf1;
DO 1 + 1, SLEEP(0);
DO @y := 9;
SELECT @y;

See also#