COLLATE
Clause in Various Parts of an SQL Query
COLLATE
Clause Precedence
BINARY
Operator
Every database has a database character set and a database
collation, which may not be null. The CREATE DATABASE
and ALTER
DATABASE
commands now have optional clauses for specifying the
database character set and collation:
CREATE DATABASE db_name [CHARACTER SET character_set_name [COLLATE collation_name]] ALTER DATABASE db_name [CHARACTER SET character_set_name [COLLATE collation_name]]
Example:
CREATE DATABASE db_name CHARACTER SET latin1 COLLATE latin1_swedish_ci;
MySQL chooses the database character set and database collation thus:
CHARACTER SET X
and COLLATE Y
were specified, then
character set X
and collation Y
.
CHARACTER SET X
was specified without COLLATE
, then
character set X
and its default collation.
MySQL's CREATE DATABASE ... CHARACTER SET ...
syntax is
analogous to the standard-SQL CREATE SCHEMA ... CHARACTER SET ...
syntax. Because of this, it is possible to create databases with
different character sets and collations, on the same MySQL
server.
The database character set and collation are used as default
values if the table character set and collation are not specified
in CREATE TABLE
statements. They have no other purpose.