Skip to content

Latest commit

 

History

History
98 lines (77 loc) · 3.59 KB

type-id-transact-sql.md

File metadata and controls

98 lines (77 loc) · 3.59 KB
title TYPE_ID (Transact-SQL) | Microsoft Docs
ms.custom
ms.date 03/14/2017
ms.prod sql
ms.prod_service database-engine, sql-database, sql-data-warehouse, pdw
ms.reviewer
ms.technology t-sql
ms.topic language-reference
f1_keywords
TYPE_ID
TYPE_ID_TSQL
dev_langs
TSQL
helpviewer_keywords
IDs [SQL Server], types
TYPE_ID function
type IDs [SQL Server]
data types [SQL Server], IDs
ms.assetid 647d17ef-b878-4922-b446-56642322ebad
author MikeRayMSFT
ms.author mikeray
monikerRange >=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current

TYPE_ID (Transact-SQL)

[!INCLUDEtsql-appliesto-ss2008-all-md]

Returns the ID for a specified data type name.

Topic link icon Transact-SQL Syntax Conventions

Syntax

TYPE_ID ( [ schema_name ] type_name )   

Arguments

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.

Return Types

int

Exceptions

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

In [!INCLUDEssNoVersion], 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.

Remarks

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

Examples

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  

Examples: [!INCLUDEssSDWfull] and [!INCLUDEssPDW]

C: 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 typeName,   
    TYPE_ID('datetime') AS typeID FROM table1;  

See Also

TYPE_NAME (Transact-SQL)
TYPEPROPERTY (Transact-SQL)
sys.types (Transact-SQL)
Metadata Functions (Transact-SQL)