TYPE_ID (Transact-SQL)

TYPE_ID (Transact-SQL)

 

THIS TOPIC APPLIES TO:yesSQL Server (starting with 2008) yesAzure SQL Database yesAzure SQL Data Warehouse yesParallel Data Warehouse

Returns the ID for a specified data type name.

Topic link icon Transact-SQL Syntax Conventions


TYPE_ID ( [ schema_name ] type_name ) 
-- Azure SQL Data Warehouse and Parallel Data Warehouse
TYPE_ID ( [ schema_name ] type_name )

type_name

Is the name of the data type. type_name is of type nvarchar. type_name can be a system or user-defined data type.

Returns NULL on error or if a caller does not have permission to view the object.

In SQL Server, a user can only view the metadata of securables that the user owns or on which the user has been granted permission. This means that metadata-emitting, built-in functions such as TYPE_ID may return NULL if the user does not have any permission on the object. For more information, see Metadata Visibility Configuration.

Exception Condition

TYPE_ID returns NULL if the type name is not valid, or if the caller does not have sufficient permission to reference the type.

The following example returns type ID for single- and two-part type names.

USE tempdb;
GO
CREATE TYPE NewType FROM int;
GO
CREATE SCHEMA NewSchema;
GO
CREATE TYPE NewSchema.NewType FROM int;
GO
SELECT TYPE_ID('NewType') AS [1 Part Data Type ID],
       TYPE_ID('NewSchema.NewType') AS [2 Part Data Type ID];
GO

The following example returns the TYPE ID for the datetime system data type.

SELECT TYPE_NAME(TYPE_ID('datetime')) AS [TYPE_NAME]
    ,TYPE_ID('datetime') AS [TYPE_ID];
GO

The following example returns the TYPE ID for the datetime system data type.

SELECT TYPE_NAME(TYPE_ID('datetime')) AS typeName, 
    TYPE_ID('datetime') AS typeID FROM table1;

Community Additions

ADD
Show:
© 2016 Microsoft