USE
SyntaxUSE db_name
The USE db_name
statement tells MySQL to use the db_name
database as the default database for subsequent queries. The database remains
current until the end of the session or until another USE
statement
is issued:
mysql> USE db1; mysql> SELECT COUNT(*) FROM mytable; # selects from db1.mytable mysql> USE db2; mysql> SELECT COUNT(*) FROM mytable; # selects from db2.mytable
Making a particular database current by means of the USE
statement
does not preclude you from accessing tables in other databases. The following example
accesses the author
table from the db1
database and the
editor
table from the db2
database:
mysql> USE db1; mysql> SELECT author_name,editor_name FROM author,db2.editor -> WHERE author.editor_id = db2.editor.editor_id;
The USE
statement is provided for Sybase compatibility.
Posted by Oscar Yen on Monday December 2 2002, @11:02pm | [Delete] [Edit] |
use `some database` will cause syntax error, why?
create database `some database` is ok, and
drop database `some database` is also ok.
Posted by Joel Kitching on Monday June 23 2003, @1:28pm | [Delete] [Edit] |
I think USE db1; works, but USE `db1`; doesn't, because USE is a "utility command". It isn't grouped with SELECT and INSERT, etc., so it must be different.