Every table has a table character set and a table collation. The
CREATE TABLE and
ALTER TABLE statements have
optional clauses for specifying the table character set and
collation:
CREATE TABLE tbl_name (column_list)
[[DEFAULT] CHARACTER SET charset_name]
[COLLATE collation_name]]
ALTER TABLE tbl_name
[[DEFAULT] CHARACTER SET charset_name]
[COLLATE collation_name]Example:
CREATE TABLE t1 ( ... )
CHARACTER SET latin1 COLLATE latin1_danish_ci;MySQL chooses the table character set and collation in the following manner:
If both
CHARACTER SETandcharset_nameCOLLATEare specified, character setcollation_namecharset_nameand collationcollation_nameare used.If
CHARACTER SETis specified withoutcharset_nameCOLLATE, character setcharset_nameand its default collation are used. To see the default collation for each character set, use theSHOW CHARACTER SETstatement or query theINFORMATION_SCHEMACHARACTER_SETStable.If
COLLATEis specified withoutcollation_nameCHARACTER SET, the character set associated withcollation_nameand collationcollation_nameare used.Otherwise (neither
CHARACTER SETnorCOLLATEis specified), the database character set and collation are used.
The table character set and collation are used as default values for column definitions if the column character set and collation are not specified in individual column definitions. The table character set and collation are MySQL extensions; there are no such things in standard SQL.