Home > Database > Mysql Tutorial > body text

MySQL优化之数据类型宽度_MySQL

WBOY
Release: 2016-06-01 13:00:04
Original
1180 people have browsed it

<span style="font-family: Arial, Verdana, sans-serif;">MYSQL中的整数型数据类型都可以指定显示宽度</span>
Copy after login
创建一个表
CREATE TABLE tb_emp( id BIGINT(1))
id字段的数据类型为BIGINT(1),注意到后面的数字1,这表示的是该数据类型指定的显示宽度,指定能够显示的数值中数字的个数。
例如,假设声明一个INT类型的字段 YEAR INT(4) ,该声明指明,在year字段中的数据一般只显示4位数字的宽度。
显示宽度和数据类型的取值范围是无关的。显示宽度只是指明MYSQL最大可能显示的数字个数,数值的位数小于指定的宽度时会有空格填充,如果插入了大于显示宽度的值,只要该值不超过该类型整数的取值范围,数值依然可以插入,而且能显示出来。
例如,向year字段插入一个数值19999,当使用select查询的时候,MYSQL显示的将是完整带有5位数字的19999,而不是4位数字的值
如果不指定显示宽度,则MYSQL为每一种类型指定默认的宽度值
注意:显示宽度只用于显示,并不能限制取值范围和占用空间,例如:INT(3)会占用4个字节的存储空间,并且允许的最大值也不会是999,而是INT整型所允许的最大值。

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!