关于information_schema中的columns表

superdingdang 2013-02-27 11:48:23
请问columns表中的NUMERIC_PRECISION和NUMERIC_SCALE指的是什么?

例子如下:

drop database d1;
create database d1;
use d1;
create table t1(a tinyint, b tinyint(1), c tinyint(2), d tinyint(3), e tinyint(4));
use information_schema;
select table_name, column_name,data_type,numeric_precision, numeric_scale, column_type from columns where table_schema='d1';


结果如下:
+------------+-------------+-----------+-------------------+---------------+-------------+
| table_name | column_name | data_type | numeric_precision | numeric_scale | column_type |
+------------+-------------+-----------+-------------------+---------------+-------------+
| t1 | a | tinyint | 3 | 0 | tinyint(4) |
| t1 | b | tinyint | 3 | 0 | tinyint(1) |
| t1 | c | tinyint | 3 | 0 | tinyint(2) |
| t1 | d | tinyint | 3 | 0 | tinyint(3) |
| t1 | e | tinyint | 3 | 0 | tinyint(4) |
+------------+-------------+-----------+-------------------+---------------+-------------+
5 rows in set (0.00 sec)

为何numeric_precision都是3呢?

...全文
354 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
superdingdang 2013-03-03
  • 打赏
  • 举报
回复
谢谢版主,请问关于第2条呢,对不对?
ACMAIN_CHM 2013-02-28
  • 打赏
  • 举报
回复
1.对于整数类型后面的括号中的数字,譬如tinyint(3),3只是对客户端显示有用 并且需要加上zerofill属性, 对存储无任何影响。 正确
rucypli 2013-02-27
  • 打赏
  • 举报
回复
NUMERIC_PRECISION Precision of approximate numeric data, exact numeric data, integer data, or monetary data. Otherwise, NULL is returned. 代表这一列精度 这一列可能是近似数字列 精确数字列 等 NUMERIC_SCALE Scale of approximate numeric data, exact numeric data, integer data, or monetary data. Otherwise, NULL is returned. 代表这一列的规模 这一列可能是近似数字列 精确数字列 等
superdingdang 2013-02-27
  • 打赏
  • 举报
回复
顶 来个人呀,困扰了好久了
superdingdang 2013-02-27
  • 打赏
  • 举报
回复
非常感谢两位的回复,终于明白了。 稍微总结了一下,不对之处还请指正: 1.对于整数类型后面的括号中的数字,譬如tinyint(3),3只是对客户端显示有用 并且需要加上zerofill属性, 对存储无任何影响。 2.整形类型的精度如下: tinyint的是3, int的是10,smallint是5,bigint的是19 精度跟各个数据类型的取值范围的数字位数对应: bigint:从 -2^63 (-9,223,372,036,854,775,808) 到 2^63-1 (9,223,372,036,854,775,807) 的整型数据(所有数字)。存储大小为 8 个字节。 int:从 -2^31 (-2,147,483,648) 到 2^31 - 1 (2,147,483,647) 的整型数据(所有数字)。存储大小为 4 个字节。int 的 SQL-92 同义字为 integer。 smallint:从 -2^15 (-32,768) 到 2^15 - 1 (32,767) 的整型数据。存储大小为 2 个字节。 tinyint:从 0 到 255 的整型数据。存储大小为 1 字节。
wwwwb 2013-02-27
  • 打赏
  • 举报
回复
The signed range is -128 to 127. The unsigned range is 0 to 255. 理解这句话的含义
superdingdang 2013-02-27
  • 打赏
  • 举报
回复
谢谢,只有3位是什么意思?
wwwwb 2013-02-27
  • 打赏
  • 举报
回复
TINYINT[(M)] [UNSIGNED] [ZEROFILL] A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255. 只有3位 NUMERIC_PRECISION tinyint 近似数字数据、精确数字数据、整型数据或货币数据的精度。否则,返回 NULL。 NUMERIC_SCALE tinyint 近似数字数据、精确数字数据、整数数据或货币数据的小数位数。否则,返回 NULL。
rucypli 2013-02-27
  • 打赏
  • 举报
回复
tinyint的是3 int的是10 smallint是5 bigint的是19 具体精度是如何来的并不清楚 求高人指点 ps 这些类型后面的括号数字只是对客户端显示有用 并且需要加上zerofill属性 对存储无任何影响
superdingdang 2013-02-27
  • 打赏
  • 举报
回复
谢谢呀 能解释一下我上面的疑问么,为何numeric_precision都是3呢?

56,678

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧