Sql-Server

在 SQL Server 中,對於數值數據類型,CHARACTER_MAXIMUM_LENGTH 可以與 NULL 不同嗎?

  • April 9, 2020

我有一個帶有幾列數字類型的 SQL Server。

獲取表結構時,我得到以下結果:

詢問:

   SELECT * 
FROM DB.INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_NAME = 'TABLE' 
 AND DATA_TYPE = 'numeric' 

結果如下(截斷):

CHARACTER_MAXIMUM_LENGTH  NUMERIC_PRECISION   NUMERIC_SCALE
NULL                     2                   0

數字的值是否CHARACTER_MAXIMUM_LENGTH 始終為 NULL ?比例和精度不會影響值的字元長度嗎?

從這個精彩的網站:

INFORMATION_SCHEMA.COLUMNS

CHARACTER_MAXIMUM_LENGTH

二進制數據、字元數據或文本和圖像數據的最大長度(以字元為單位)。-1 用於 xml 和大值類型數據。否則,返回 NULL。有關詳細資訊,請參閱

數據類型 (Transact-SQL)

Column name      Data type      Description
TABLE_CATALOG   nvarchar(128)   Table qualifier.
TABLE_SCHEMA    nvarchar(128)   Name of schema that contains the table.
TABLE_NAME      nvarchar(128)   Table name.
COLUMN_NAME     nvarchar(128)   Column name.
ORDINAL_POSITION    int Column identification number.
Note: In SQL Server 2005, these column IDs are consecutive numbers.

COLUMN_DEFAULT              nvarchar(4000)  Default value of the column.
IS_NULLABLE                 varchar(3)  Nullability of the column. 
                           If this column allows for NULL, this column returns YES. Otherwise, NO is returned.
DATA_TYPE                   nvarchar(128)   System-supplied data type.
CHARACTER_MAXIMUM_LENGTH    int Maximum length, in characters, for binary data, character data, or text and image data.
-1 for xml and large-value type data. Otherwise, NULL is returned. For more information, see Data Types (Transact-SQL).

CHARACTER_OCTET_LENGTH      int Maximum length, in bytes, for binary data, character data, or text and image data.
-1 for xml and large-value type data. Otherwise, NULL is returned.

NUMERIC_PRECISION           tinyint Precision of approximate numeric data, exact numeric data, integer data, or monetary data. Otherwise, NULL is returned.
NUMERIC_PRECISION_RADIX     smallint    Precision radix of approximate numeric data, exact numeric data, integer data, or monetary data. Otherwise, NULL is returned.
NUMERIC_SCALE               int Scale of approximate numeric data, exact numeric data, integer data, or monetary data. Otherwise, NULL is returned.
DATETIME_PRECISION          smallint    Subtype code for datetime and SQL-92 interval data types. For other data types, NULL is returned.
CHARACTER_SET_CATALOG       nvarchar(128)   Returns master. This indicates the database in which the character set is located, if the column is character data or text data type. Otherwise, NULL is returned.
CHARACTER_SET_SCHEMA        nvarchar(128)   Always returns NULL.
CHARACTER_SET_NAME         nvarchar(128)    Returns the unique name for the character set if this column is character data or text data type. Otherwise, NULL is returned.
COLLATION_CATALOG         nvarchar(128) Always returns NULL.
COLLATION_SCHEMA          nvarchar(128) Always returns NULL.
COLLATION_NAME            nvarchar(128) Returns the unique name for the collation if the column is character data or text data type. Otherwise, NULL is returned.
DOMAIN_CATALOG            nvarchar(128) If the column is an alias data type, this column is the database name in which the user-defined data type was created. Otherwise, NULL is returned.
DOMAIN_SCHEMA             nvarchar(128) If the column is a user-defined data type, this column returns the name of the schema of the user-defined data type. Otherwise, NULL is returned.
DOMAIN_NAME               nvarchar(128) If the column is a user-defined data type, this column is the name of the user-defined data type. Otherwise, NULL is returned.

引用自:https://dba.stackexchange.com/questions/264662