1. Decimal type is decimal, float and double are prohibited.
float and double have the problem of precision loss during storage, and incorrect results are likely to be obtained when comparing values.
2. If the range of stored data exceeds the range of decimal, it is recommended to split the data into integers and decimals and store them separately.
3. Use tinyint/int/bigint according to business classification, occupying 1/4/8 bytes respectively.
Char/varchar is used according to business differentiation.
Example
Demo: mysql> use school; #选择数据库school mysql> create table class6(class_id integer(5) zerofill, class_name varchar(128), class_teacher varchar(64) ); #创建表class6 mysql> insert into class0 values(1,'三年级六班','张老师'); mysql> select * from class0 ; +-------+------------+---------+ | id | name | teacher | +-------+------------+---------+ | 00001 | 三年级六班 | 张老师 | +-------+------------+---------+ 1 row in set (0.00 sec)
The above is the detailed content of What are the usage specifications of mysql columns?. For more information, please follow other related articles on the PHP Chinese website!