| title | Create a Database Master Key | Microsoft Docs | |
|---|---|---|
| description | Create a database master key in SQL Server by using Transact-SQL. Be sure you have the required permissions. | |
| ms.custom | ||
| ms.date | 09/12/2019 | |
| ms.prod | sql | |
| ms.prod_service | database-engine, sql-database, synapse-analytics, pdw | |
| ms.reviewer | vanto | |
| ms.technology | security | |
| ms.topic | conceptual | |
| helpviewer_keywords |
|
|
| ms.assetid | 8cb24263-e97d-4e4d-9429-6cf494a4d5eb | |
| author | jaszymas | |
| ms.author | jaszymas | |
| monikerRange | >=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current |
[!INCLUDE SQL Server] This topic describes how to create a database master key in [!INCLUDEssnoversion] by using [!INCLUDEtsql].
Requires CONTROL permission on the database.
-
Choose a password for encrypting the copy of the master key that will be stored in the database.
-
In Object Explorer, connect to an instance of [!INCLUDEssDE].
-
Expand System Databases, right-click
masterand then click New Query. -
Copy and paste the following example into the query window and click Execute.
-- Creates the master key. -- The key is encrypted using the password "23987hxJ#KL95234nl0zBe". CREATE MASTER KEY ENCRYPTION BY PASSWORD = '23987hxJ#KL95234nl0zBe';
For more information, see CREATE MASTER KEY (Transact-SQL).