KEY_ID (Transact-SQL)

**APPLIES TO:** ![yes](media/yes.png)SQL Server (starting with 2008) ![yes](media/yes.png)Azure SQL Database ![no](media/no.png)Azure SQL Data Warehouse ![no](media/no.png)Parallel Data Warehouse

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

Topic link icon 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