Mysql 三大列类型
数值型
整型
Tinyint 、 Smallint、 Mediumint 、 Int、 Bigint
小数型
Float(D,M),Decimal(D,M)
字符串型
Char(M)
Varchar(M)
Text 文本类型
日期时间类型
Date 日期
Time 时间
Datetime 时间类型
Year年类型
一. 整型列的字节与存储范围
从数学上讨论 tinyint ,建表时既能足够存放,又不浪费
空间。
即:
. 占据空间
. 存储范围
Tinyint微小的列类型,1字节
字节
最小值
最大值
(带符号/无符号)
(带符号/无符号)
Tinyint
1
-128
127
0
255
Smallint
2
-32768
32767
0
65535
Mediumint
3
-2八23
2八23-1
0
2八24-1
Int
4
-2八31
2八31-1
0
2八32-1
Bigint
8
-2八63
2八63-1
0
2八64-1
通过占用字节和所存范围分关系合理的选择类型
例:Tinyint
my号ql) table t^st(
> id int primary key auto_increment s
> name uarchar(10)P
> age tinyintjcharset : utfS; Query OK, G rows affected (0 J 6 写ec)
gaql〉insert into “日lues('张三,,NO0');
uery OK, 1 row affected, 1 warning (€ sac) ysql> select k from tost;
id I name I age I
I张三 I 25 I
I 藤三 I 127 I
rows in set ( sec)
insert into te5t(rwmeqge) udluw5('张三’J 729'); OK, 1 row affected, 1 warning ( tec)
select m from test;
id | name | age
三三一二 长长长 Bf- _d7
row5 in s&t ( c电匕)
经测试,Tinyint的默认为有符号-128~127之间,当越界时自动取相应
的边界值。若要存0~255无符号时:
列的可选属性:
Tinyint(M) unsigned zerofill.
M:宽度(在。填充的时候才有意义)
Unsigned:无符号类型(非负),影响存储范围
Zerofill: 0填充(默认无符号)
mysql) alter table to«t add age3 tinyint(5) zorofill; Query OK, 8 rows affected ( sec) Records j 8 Duplicates: 0 Warnings: 0
mycql> decc tect ;
I Field I Type
I Null I Key I Default I Extra
age
age3
uarchar(19)
tinyint(M)
tinyint(3) unsigned
tinyint(1)
tinyint(5) unsigned zerofil1
NO
VES
VES
YES
VES
VES
PRI I NULL
I NULL
I NULL
I NULL
I NULL
I NULL
auto increment
6 rows in set ( sec)
mysql> insert into test(name9age1) ualuos('张三‘,’2。®'); Query OK, 1 row affected ( sec) myeql> insert into test(name,age1) u&Iuqs(‘李四‘,‘7。。’); Query OK, 1 row affected, 1 warning ( sec) mysql> select 乂 From test;
+ - + + +
I id I name I age I age1 I + + + + 4
12 3 4 5 6 7
三三三三四三四
张张张张李张李
25
12
Mysql燕十八学习笔记 来自淘豆网m.daumloan.com转载请标明出处.