Home > Database > Mysql Tutorial > body text

基于mysq字段选择的详解_MySQL

WBOY
Release: 2016-06-01 13:24:53
Original
724 people have browsed it

bitsCN.com

mysql支持很多字段类型,包括数值类型、日期/时间类型和字符串(字符)类型;在使用时需要考虑到存储空间,存储效率;
几种列类型描述使用了下述惯例:
  M
表示最大显示宽度。最大有效显示宽度是255。
  D
时间类型:datetime(8bytes),timestamp(4bytes)
字符类型:
VARCHAR(M),L+1个字节,其中LCHAR(M)M个字节,0 BINARY(M),M个字节,0 VARBINARY(M),L+1个字节,其中L ENUM('value1','value2',...),1或2个字节,取决于枚举值的个数(最多65,535个值),调整比较复杂,需要先drop在create;在枚举值小于255时,占1个字节,大于255时占2个字节;
SET('value1','value2',...)1、2、3、4或者8个字节,取决于set成员的数目(最多64个成员),1-8占1个字节,9-16占2个字节,17-24占3个字节,25-32占4个字节,33-64占8个字节;
整型类型:
tinyint(8),一个字节
smallint(16),2个字节
mediumint(24),3个字节
int(32),4个字节
bigint(64),8个字节
实型类型:
float(4bytes)
Float(M,D)  单精度浮点型,精确到小数点后面6位,双精度double(M,D)精确到小数点后面13位;
float 内存如何存储
        
类型
 存储位数
 总位数
 偏移值

 数符(S)
 阶码(E)
 尾数(M)
 (offset)

短实数(float)
    1
    8
   23
    32
 127

长实数(double)
    1
    11
   52
    64
  1023

Float怎么存储
N (10) = 123.456,
换算成二进制表示:
N (2) = 1111011. 01110100101111001
= 1. 11101101110100101111001(...) * 2^6
 那么 E = 127 + 6 = 133(10) = 10000101(2)
M = 111 0110 1110 1001 0111 1001 (省略了最高数字位1, 共23bit)
 组合起来就是:
S         E                       M
0        10000101     111 0110 1110 1001 0111 1001

整型类型:
Decimal(M,D)占M+2个字节,小数点和符号需要
各自占一个字节;
DECIMAL 可能的最大取值范围与DOUBLE 一样
,但是其有效的取值范围由M 和D 的值决定,存蓄
的方式是字符串;
Decimal(M,D)占M+2个字节,小数点和符号需要各自占一个字节;
DECIMAL 可能的最大取值范围与DOUBLE 一样,但是其有效的取值范围由M 和D 的值决定,存蓄的方式是字符串;

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!