A data type that stores values of various SQL Server-supported data types, except text, ntext, image, timestamp, and sql_variant.
sql_variant may be used in columns, parameters, variables, and return values of user-defined functions. sql_variant allows these database objects to support values of other data types.
sql_variant
A column of type sql_variant may contain rows of different data types. For example, a column defined as sql_variant can store int, binary, and char values. The only types of values that cannot be stored using sql_variant are text, ntext, image, timestamp, and sql_variant.
sql_variant can have a maximum length of 8016 bytes.
An sql_variant data type must first be cast to its base data type value before participating in operations such as addition and subtraction.
sql_variant may be assigned a default value. This data type also may have NULL as its underlying value, but the NULL values will not have an associated base type. In addition, sql_variant may not have another sql_variant as its base type.
A UNIQUE, primary, or foreign key may include columns of type sql_variant, but the total length of the data values comprising the key of a given row should not be greater than the maximum length of an index (currently 900 bytes).
A table may have any number of sql_variant columns.
sql_variant cannot be used in CONTAINSTABLE and FREETEXTTABLE.
ODBC does not fully support sql_variant. Hence, queries of sql_variant columns are returned as binary data when using Microsoft OLE DB Provider for ODBC (MSDASQL). For example, an sql_variant column containing the character string data 'PS2091' is returned as 0x505332303931.
The sql_variant data type belongs to the top of the data type hierarchy list for conversion. For sql_variant comparisons, the SQL Server data type hierarchy order is grouped into data type families.
Data Type Hierarchy | Data Type Family |
sql_variant | sql_variant |
datetime | datetime |
smalldatetime | datetime |
float | approximate number |
real | approximate number |
decimal | exact number |
money | exact number |
smallmoney | exact number |
bigint | exact number |
int | exact number |
smallint | exact number |
tinyint | exact number |
bit | exact number |
nvarchar | Unicode |
nchar | Unicode |
varchar | Unicode |
char | Unicode |
varbinary | binary |
binary | binary |
uniqueidentifier | uniqueidentifier |
These rules apply to sql_variant comparisons: