Table Character Set and Collation
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 TABLEtbl_name(column_list) [[DEFAULT] CHARACTER SETcharset_name] [COLLATEcollation_name]] ALTER TABLEtbl_name[[DEFAULT] CHARACTER SETcharset_name] [COLLATEcollation_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 SETandXCOLLATEare specified, character setYXand collationYare used. - If
CHARACTER SETis specified withoutXCOLLATE, character setXand its default collation are used. To see the default collation for each character set, use theSHOW COLLATIONstatement. - If
COLLATEis specified withoutYCHARACTER SET, the character set associated withYand collationYare used. - Otherwise, 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 MariaDB extensions; there are no such things in standard SQL.