10bet网址
MySQL 5.7 Reference Manual
Related Documentation Download this Manual Excerpts from this Manual

10.3.4 Table Character Set and Collation

Every table has a table character set and a table collation. TheCREATE TABLEandALTER TABLEstatements 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 bothCHARACTER SETcharset_nameandCOLLATEcollation_nameare specified, character setcharset_nameand collationcollation_nameare used.

  • IfCHARACTER SETcharset_nameis specified withoutCOLLATE, 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.

  • IfCOLLATEcollation_nameis specified withoutCHARACTER SET, the character set associated withcollation_nameand collationcollation_nameare used.

  • Otherwise (neitherCHARACTER 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.