创建数据库主密钥Create a Database Master Key

适用对象:SQL Server 是Azure SQL 数据库 是Azure Synapse Analytics (SQL DW) 是并行数据仓库APPLIES TO: yesSQL Server yesAzure SQL Database yesAzure Synapse Analytics (SQL DW) yesParallel Data Warehouse

本主题说明如何使用 SQL Server 2019 (15.x)SQL Server 2019 (15.x)Transact-SQLTransact-SQL中创建数据库主密钥。This topic describes how to create a database master key in SQL Server 2019 (15.x)SQL Server 2019 (15.x) by using Transact-SQLTransact-SQL.

安全性Security

权限Permissions

要求对数据库具有 CONTROL 权限。Requires CONTROL permission on the database.

“使用 Transact-SQL”Using Transact-SQL

创建数据库主密钥To create a database master key

  1. 选择密码来对存储于该数据库中的主密钥副本进行加密。Choose a password for encrypting the copy of the master key that will be stored in the database.

  2. “对象资源管理器” 中,连接到 数据库引擎Database Engine的实例。In Object Explorer, connect to an instance of 数据库引擎Database Engine.

  3. 展开“系统数据库”,右键单击 ,然后单击“新建查询” masterExpand System Databases, right-click master and then click New Query.

  4. 将以下示例复制并粘贴到查询窗口中,然后单击“执行” 。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';  
    
    

有关详细信息,请参阅 CREATE MASTER KEY (Transact-SQL)For more information, see CREATE MASTER KEY (Transact-SQL).