What does “numeric precision radix” mean in the SQL Server metadata?

旧城冷巷雨未停 提交于 2020-01-02 04:05:35

问题


I am browsing the SQL Server Management Studio Object Explorer: the metadata. Under the TempDb > Views > System Views > Columns object I find: "Numeric Precision Radix". I know what radix means (binary, decimal, hexidecimal, etc) and what Numeric Precision means (how many digits are in the representation of the number, and Scale: how many digits are after the radix point).

But how can the metadata itself (Numeric Precision) have a Radix (system of encoding)? It is like saying what color is the CAN of paint?

And why can't I find a description of this phrase anywhere? Thank you.


回答1:


I believe that Numeric_Precision_Radix is specified in the Information_Schema.Columns table as specified by the SQL-99 standard.

It will be different for each DBMS. according to this link it is specified as:

If data_type identifies a numeric type, this column indicates in which base the values in the columns numeric_precision and numeric_scale are expressed. The value is either 2 or 10. For all other data types, this column is null.

For SQL Server it is 10 for int, money and decimal and 2 for float & real. See below for example where for float where the radix is 2 and the precision is 53, meaning that the it is precise to 53 bits of information.

In other words for int precision is expressed in terms 10 to the power of 10 but for real it is expressed as 2 to the power of 53.

See wiki link here

SQL Fiddle

MS SQL Server 2008 Schema Setup:

CREATE TABLE MyRadix
(
    aInt int,
    bFloat float,
    cMoney Money,
    dDecimal Decimal(12,10),
    eReal Real
)

Query 1:

SELECT COLUMN_NAME, DATA_TYPE, NUMERIC_PRECISION_RADIX, NUMERIC_PRECISION, NUMERIC_SCALE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'MyRAdix'

Results:

| COLUMN_NAME | DATA_TYPE | NUMERIC_PRECISION_RADIX | NUMERIC_PRECISION | NUMERIC_SCALE |
|-------------|-----------|-------------------------|-------------------|---------------|
|        aInt |       int |                      10 |                10 |             0 |
|      bFloat |     float |                       2 |                53 |        (null) |
|      cMoney |     money |                      10 |                19 |             4 |
|    dDecimal |   decimal |                      10 |                12 |            10 |
|       eReal |      real |                       2 |                24 |        (null) |


来源:https://stackoverflow.com/questions/28835640/what-does-numeric-precision-radix-mean-in-the-sql-server-metadata

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!