tinyint,smallint,int,bigint后面括号的含义

tinyint存1个字节(unsigned 存0--255,无 存-128 --127) smallint存2个字节(unsigned 存0—65535 ,无 存-32768--32767) int存4个字节(unsigned 存2的32次方,无 存-2的31次方 –2的31次方-1) bigint存8个字节(unsigned 存2的64次方,无 存-2的63次方 –2的63次方-1)

做个实验: mysql> create table bb(a int(1) zerofill,b int(2) zerofill,c int(3) zerofill); Query OK, 0 rows affected (0.18 sec) mysql> show create table bb; CREATE TABLE bb ( aint(1) unsigned zerofill DEFAULT NULL, b int(2) unsigned zerofill DEFAULT NULL, cint(3) unsigned zerofill DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 三个字段括号中的参数不同,分别都加了zerofill,我们来看下有什么影响 mysql> insert into bb values(1,1,1); Query OK, 1 row affected (0.00 sec)

mysql> select * from bb;

abc
101001

1 row in set (0.00 sec)

mysql> alter table bb add d int(4); Query OK, 1 row affected (0.27 sec) Records: 1 Duplicates: 0 Warnings: 0

mysql> select * from bb;

abcde
101001NULLNULL

1 row in set (0.00 sec)

mysql> update bb set d =1,e =1 where a=1; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from bb;

abcde
10100111

1 row in set (0.00 sec)

由此可见:括号中的数字表示数据库中显示数字的位数,一般情况下不起左右,只有在zerofill情况下才会起作用。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值