MySQL数据类型int(4)的长度4究竟有什么意义

  • 一个int类型占用4字节是固定的,但是MySQL里的长度设置有什么意义?
  • 网上都说是会补0,但是我试了试也没看见补0,那他的补0是啥意思
  • 官方手册似乎没有提到这个问题,翻了好久并没有看到解释
阅读 2k
1 个回答

补 0 是对的,但你需要给这列设置 UNSIGNED ZEROFILL 才会填充。

REF: https://dev.mysql.com/doc/ref...
 
MySQL provides an extension that allows you to specify the display width along with the INT datatype. The display width is wrapped inside parentheses following the INT keyword e.g., INT(5) specifies an INT with the display width of five digits.
 
It is important to note that the display width attribute does not control the value ranges that the column can store. The display width attribute is typically used by the applications to format the integer values. MySQL includes the display width attribute as the metadata of the returned result set.
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题