Rediger

Del via


OPEN MASTER KEY (Transact-SQL)

Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics Analytics Platform System (PDW)

Opens the Database Master Key of the current database.

Transact-SQL syntax conventions

Syntax

OPEN MASTER KEY DECRYPTION BY PASSWORD = 'password'   

Note

This syntax is not supported by serverless SQL pool in Azure Synapse Analytics.

Arguments

'password'
The password with which the Database Master Key was encrypted.

Remarks

If the database master key was encrypted with the service master key, it will be automatically opened when it is needed for decryption or encryption. In this case, it is not necessary to use the OPEN MASTER KEY statement.

When a database is first attached or restored to a new instance of SQL Server, a copy of the database master key (encrypted by the service master key) is not yet stored in the server. You must use the OPEN MASTER KEY statement to decrypt the database master key (DMK). Once the DMK has been decrypted, you have the option of enabling automatic decryption in the future by using the ALTER MASTER KEY REGENERATE statement to provision the server with a copy of the DMK, encrypted with the service master key (SMK). When a database has been upgraded from an earlier version, the DMK should be regenerated to use the newer AES algorithm. For more information about regenerating the DMK, see ALTER MASTER KEY (Transact-SQL). The time required to regenerate the DMK key to upgrade to AES depends upon the number of objects protected by the DMK. Regenerating the DMK key to upgrade to AES is only necessary once, and has no impact on future regenerations as part of a key rotation strategy.

You can exclude the Database Master Key of a specific database from automatic key management by using the ALTER MASTER KEY statement with the DROP ENCRYPTION BY SERVICE MASTER KEY option. Afterward, you must explicitly open the Database Master Key with a password.

If a transaction in which the Database Master Key was explicitly opened is rolled back, the key will remain open.

Permissions

Requires CONTROL permission on the database.

Examples

The following example opens the Database Master Key of the AdventureWorks2022 database, which has been encrypted with a password.

USE AdventureWorks2022;  
OPEN MASTER KEY DECRYPTION BY PASSWORD = '43987hkhj4325tsku7';  
GO  

Examples: Azure Synapse Analytics and Analytics Platform System (PDW)

The following example opens the database master, which has been encrypted with a password.

USE master;  
OPEN MASTER KEY DECRYPTION BY PASSWORD = '43987hkhj4325tsku7';  
GO  
CLOSE MASTER KEY;  
GO  

See Also