Max*_*Max 8 sql-server-2008-r2
我运行了以下脚本来为我创建的其中一个数据库创建主密钥,但是我无法在节点中看到它们的密钥(请参阅快照); 有谁知道为什么?我期待着听到你的回复,谢谢.
USE AdventureWorks
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD = '23987hxJ#KL95234nl0zBe'
GO
Run Code Online (Sandbox Code Playgroud)

Ada*_*ger 16
您无法在SSMS GUI中看到此信息,但如果运行以下命令,则可以查看数据库是否具有主密钥:
SELECT d.is_master_key_encrypted_by_server
FROM sys.databases AS d
WHERE d.name = 'AdventureWorks';
Run Code Online (Sandbox Code Playgroud)
这是测试DMK是否存在的两种方法。
请注意,sys.databases中的[is_master_key_encrypted_by_server]列可以显示0,但是DMK存在并且已被SMK加密删除。
我希望这有帮助。
======================
-- Test for existence of a DMK. If it does not exist, then create it.
-- Method 1:
IF (SELECT COUNT(*) FROM sys.symmetric_keys WHERE name LIKE '%DatabaseMasterKey%') = 0
BEGIN
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'ljlLKJjs$2@l23je'
END
-- Method 2:
IF NOT EXISTS (SELECT * FROM sys.symmetric_keys WHERE name LIKE '%DatabaseMasterKey%')
BEGIN
SELECT 'DMK does not exist'
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'ljlLKJjs$2@l23je'
END
ELSE
BEGIN
SELECT 'DMK exists'
END
-- Demo showing that is_master_key_encrypted_by_server in sys.databases does not show whether the DMK exists or not.
DROP MASTER KEY
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'ljlLKJjs$2@l23je'
GO
SELECT is_master_key_encrypted_by_server, name
FROM sys.databases
WHERE name = 'GalaxianTest1'
--> is_master_key_encrypted_by_server name
--> 1 GalaxianTest1
USE GalaxianTest1
GO
-- This command causes the DMK to not be encrypted by the SMK.
ALTER MASTER KEY DROP ENCRYPTION BY SERVICE MASTER KEY
-- This command now shows 0, although the DMK still exists.
SELECT is_master_key_encrypted_by_server, name
FROM sys.databases
WHERE name = 'GalaxianTest1'
--> is_master_key_encrypted_by_server name
--> 0 GalaxianTest1
-- Try creating a new DMK. This will error because the DMK still exists.
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'ljlLKJjs$2@l23je'
GO
--> Error: There is already a master key in the database. Please drop it before performing this statement.
DROP MASTER KEY
GO
--> Command(s) completed successfully.
SELECT is_master_key_encrypted_by_server, name
FROM sys.databases
WHERE name = 'GalaxianTest1'
--> is_master_key_encrypted_by_server name
--> 0 GalaxianTest1
-- Note: this is the same message as above when the DMK existed, but had been dropped from encryption by service master key.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21552 次 |
| 最近记录: |