Applies To: SQL Server 2014, SQL Server 2016 Preview
Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to existing features in Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2).
Returns the ID for a specified data type name.
Applies to: SQL Server (SQL Server 2008 through current version), Azure SQL Database, Azure SQL Data Warehouse Public Preview.
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.
A. Looking up the TYPE ID values for single- and two-part type names
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
B. Looking up the TYPE ID of a system data type
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