sp_describe_first_result_set#

Returns the metadata for the first result set of the T-SQL batch. Returns an empty result set if the batch returns no results. Raises an error if the Engine cannot determine the metadata for the first query that will be executed by performing a static analysis.

Arguments#

  • @tsql - One or more Transact-SQL statements. Transact-SQL_batch may be nvarchar(n) or nvarchar(max).

Result Sets#

This common metadata is returned as a result set with one row for each column in the results metadata. Each row describes the type and nullability of the column in the format described below.

Column name

Data type

Description

is_hidden

bit NOT NULL

Indicates that the column is an extra column added for browsing information purposes and that it does not appear in the result set.

column_ordinal

int NOT NULL

Contains the ordinal position of the column in the result set. The first column’s position will be specified as 1.

name

sysname NULL

Contains the name of the column if a name can be determined. Otherwise, it will contain NULL.

is_nullable

bit NOT NULL

Contains the value 1 if the column allows NULLs, 0 if the column does not allow NULLs, and 1 if it cannot be determined if the column allows NULLs.

system_type_id

int NOT NULL

Contains the system_type_id of the data type of the column as specified in sys.types.

system_type_name

nvarchar(256) NULL

Contains the name and arguments (eg. length, precision, scale), specified for the data type of the column. If the data type is a user-defined alias type, the underlying system type is specified here.

max_length

smallint NOT NULL

Maximum length (in bytes) of the column. -1 = Column data type is varchar(max), nvarchar(max), varbinary(max), or xml.

precision

tinyint NOT NULL

Precision of the column if numeric-based. Otherwise returns 0.

scale

tinyint NOT NULL

Scale of column if numeric-based. Otherwise returns 0.

collation_name

sysname NULL

Name of the collation of the column if character-based. Otherwise returns NULL.

user_type_id

int NULL

Unused, always NULL.

user_type_database

sysname NULL

Unused, always NULL.

user_type_schema

sysname NULL

Unused, always NULL.

user_type_name

sysname NULL

Unused, always NULL.

assembly_qualified_type_name

nvarchar(4000)

Unused, always NULL.

xml_collection_id

int NULL

Unused, always NULL.

xml_collection_database

sysname NULL

Unused, always NULL.

xml_collection_schema

sysname NULL

Unused, always NULL.

xml_collection_name

sysname NULL

Unused, always NULL.

is_xml_document

bit NOT NULL

Unused, always NULL.

is_case_sensitive

bit NOT NULL

Returns 1 if the column is a case-sensitive string type and 0 if it is not.

is_fixed_length_clr_type

bit NOT NULL

Unused, always NULL.

source_server

sysname

Unused, always NULL.

source_database

sysname

Unused, always NULL.

source_schema

sysname

Unused, always NULL.

source_table

sysname

Unused, always NULL.

source_column

sysname

Unused, always NULL.

is_identity_column

bit NULL

Returns 1 if the column is an identity column and 0 if not. Returns NULL if it cannot be determined that the column is an identity column.

is_part_of_unique_key

bit NULL

Always 0.

is_updateable

bit NULL

Always 1.

is_computed_column

smallint NULL

Always 0.

is_sparse_column_set

smallint NULL

Always 0.

ordinal_in_order_by_list

smallint NULL

Unused, always NULL.

order_by_list_length

smallint NULL

Unused, always NULL.

order_by_is_descending

smallint NULL

Unused, always NULL.

tds_type_id

int NOT NULL

For internal use.

tds_length

int NOT NULL

For internal use.

tds_collation_id

int NULL

For internal use.

tds_collation_sort_id

tinyint NULL

For internal use.

Permissions#

Requires permission to execute the @tsql argument.

Example#

The following example describes the result set returned from a single query.

EXEC sp_describe_first_result_set @tsql=N'select * from MyView'