SQL_VARIANT_PROPERTY (Transact-SQL)
返回有關 sql_variant 值的基礎資料型別 (Elementary Data Type)和其他資訊。
Transact-SQL 文法約定
{
ExpandCollapse(syntaxToggle)
}" onkeypress="function onkeypress()
{
ExpandCollapse_CheckKey(syntaxToggle)
}">文法
| |
SQL_VARIANT_PROPERTY ( expression , property ) |
{
ExpandCollapse(sectionToggle0)
}" onkeypress="function onkeypress()
{
ExpandCollapse_CheckKey(sectionToggle0)
}">參數
-
expression
-
類型為 sql_variant 的運算式。
-
property
-
包含將為其提供資訊的 sql_variant 屬性的名稱。property 的資料類型為 varchar(128),可以是下列值之一。
| 值 |
說明 |
返回的 sql_variant 基本類型 |
BaseType |
SQL Server 資料類型,例如: bigint binary char date datetime datetime2 datetimeoffset decimal float int money nchar numeric nvarchar real smalldatetime smallint smallmoney time tinyint uniqueidentifier varbinary varchar |
sysname NULL = 輸入無效。 |
Precision |
數值基礎資料型別 (Elementary Data Type)的位元: datetime = 23 smalldatetime = 16 float = 53 real = 24 decimal (p,s) 和 numeric (p,s) = p money = 19 smallmoney = 10 bigint = 19 int = 10 smallint = 5 tinyint = 3 bit = 1 所有其他類型 = 0 |
int NULL = 輸入無效。 |
Scale |
數值基礎資料型別 (Elementary Data Type)的小數點後的位元: decimal (p,s) 和 numeric (p,s) = s money 和 smallmoney = 4 datetime = 3 所有其他類型 = 0 |
int NULL = 輸入無效。 |
TotalBytes |
同時容納值的中繼資料和資料所需的位元組數。在檢查 sql_variant 列中資料的最大一側時,該資訊很有用。如果該值大於 900,則索引建立將失敗。 |
int NULL = 輸入無效。 |
Collation |
代表特定 sql_variant 值的定序。 |
sysname NULL = 輸入無效。 |
MaxLength |
最大資料類型長度(位元組)。例如,nvarchar(50) 的 MaxLength 是 100,int 的 MaxLength 是 4。 |
int NULL = 輸入無效。 |
{
ExpandCollapse(sectionToggle1)
}" onkeypress="function onkeypress()
{
ExpandCollapse_CheckKey(sectionToggle1)
}">傳回型別
sql_variant
{
ExpandCollapse(sectionToggle2)
}" onkeypress="function onkeypress()
{
ExpandCollapse_CheckKey(sectionToggle2)
}">樣本
以下樣本檢索有關 colA 的 SQL_VARIANT_PROPERTY 資訊。
| |
{ CopyCode(this) }" onmouseover="function onmouseover() { ChangeCopyCodeIcon(this) }" onmouseout="function onmouseout() { ChangeCopyCodeIcon(this) }" onkeypress="function onkeypress() { CopyCode_CheckKey(this) }"> |
CREATE TABLE tableA(colA sql_variant, colB int) INSERT INTO tableA VALUES ( cast (46279.1 as decimal(8,2)), 1689) INSERT INTO tableA VALUES ( 'abcde' ,1700 ) INSERT INTO tableA VALUES ( $5.88 ,1700 ) SELECT SQL_VARIANT_PROPERTY(colA,'BaseType') AS 'Base Type', SQL_VARIANT_PROPERTY(colA,'Precision') AS 'Precision', SQL_VARIANT_PROPERTY(colA,'Scale') AS 'Scale', SQL_VARIANT_PROPERTY(colA,'MaxLength') AS 'MaxLength' FROM tableA 下面是結果集:請注意,這三個值中的每一個都是 sql_variant。 /* Base Type Precision Scale MaxLength decimal 8 2 5 varchar 0 0 8000 money 19 4 8 */ DROP TABLE tableA
|
| |
{ CopyCode(this) }" onmouseover="function onmouseover() { ChangeCopyCodeIcon(this) }" onmouseout="function onmouseout() { ChangeCopyCodeIcon(this) }" onkeypress="function onkeypress() { CopyCode_CheckKey(this) }"> |
|