SQL查詢有關 sql_variant 值的基礎資料型別 (Elementary Data Type)和其他資訊

來源:互聯網
上載者:User

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

moneysmallmoney = 4

datetime = 3

所有其他類型 = 0

int

NULL = 輸入無效。

TotalBytes

同時容納值的中繼資料和資料所需的位元組數。在檢查 sql_variant 列中資料的最大一側時,該資訊很有用。如果該值大於 900,則索引建立將失敗。

int

NULL = 輸入無效。

Collation

代表特定 sql_variant 值的定序。

sysname

NULL = 輸入無效。

MaxLength

最大資料類型長度(位元組)。例如,nvarchar(50)MaxLength 是 100,intMaxLength 是 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)
}">

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.