请问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呢?
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呢?
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.
代表这一列的规模 这一列可能是近似数字列 精确数字列 等
int的是10
smallint是5
bigint的是19具体精度是如何来的并不清楚 求高人指点ps 这些类型后面的括号数字只是对客户端显示有用 并且需要加上zerofill属性 对存储无任何影响
只有3位
NUMERIC_PRECISION tinyint 近似数字数据、精确数字数据、整型数据或货币数据的精度。否则,返回 NULL。NUMERIC_SCALE tinyint 近似数字数据、精确数字数据、整数数据或货币数据的小数位数。否则,返回 NULL。
理解这句话的含义
稍微总结了一下,不对之处还请指正:
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 字节。
正确