Skip to content

Latest commit

 

History

History
73 lines (57 loc) · 2.52 KB

key-id-transact-sql.md

File metadata and controls

73 lines (57 loc) · 2.52 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic ms.custom f1_keywords helpviewer_keywords dev_langs monikerRange
KEY_ID (Transact-SQL)
KEY_ID (Transact-SQL)
VanMSFT
vanto
03/06/2017
sql
t-sql
reference
ignite-2024
Key_ID
Key_ID_TSQL
identification numbers [SQL Server], symmetric keys
KEY_ID function
symmetric keys [SQL Server], IDs
IDs [SQL Server], symmetric keys
TSQL
=azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric

KEY_ID (Transact-SQL)

[!INCLUDE SQL Server Azure SQL Database Azure SQL Managed Instance FabricSQLDB]

Returns the ID of a symmetric key in the current database.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

Key_ID ( 'Key_Name' )  

Arguments

' Key_Name '
The name of a symmetric key in the database.

Return Types

int

Remarks

The name of a temporary key must start with a number sign (#).

Permissions

Because temporary keys are only available in the session in which they are created, no permissions are required to access them. To access a key that is not temporary, the caller needs some permission on the key and must not have been denied VIEW permission on the key.

Examples

A. Returning the ID of a symmetric key

The following example returns the ID of a key called ABerglundKey1.

SELECT KEY_ID('ABerglundKey1');  

B. Returning the ID of a temporary symmetric key

The following example returns the ID of a temporary symmetric key. Note that # is prepended to the key name.

SELECT KEY_ID('#ABerglundKey2');  

See Also

KEY_GUID (Transact-SQL)
CREATE SYMMETRIC KEY (Transact-SQL)
sys.symmetric_keys (Transact-SQL)
sys.key_encryptions (Transact-SQL)
Encryption Hierarchy