Created
May 30, 2018 14:13
-
-
Save mikerodionov/7a1763e942b965342f632be6cceef05a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE master; | |
GO | |
IF (select Count(*) from sys.symmetric_keys where name like '%DatabaseMasterKey%') = 0 | |
BEGIN | |
CREATE MASTER KEY ENCRYPTION BY PASSWORD='P@ssw0rd'; | |
END | |
GO | |
IF (select Count(*) from sys.certificates where name = 'TdeCertificate') = 0 | |
BEGIN | |
CREATE CERTIFICATE TdeCertificate WITH SUBJECT='TDE Certificate' | |
END | |
GO | |
USE [K2]; | |
GO | |
IF (SELECT Count(*) FROM sys.dm_database_encryption_keys WHERE database_id=(SELECT DB_ID('tempdb'))) = 0 | |
BEGIN | |
CREATE DATABASE ENCRYPTION KEY | |
WITH ALGORITHM = AES_128 | |
ENCRYPTION BY SERVER CERTIFICATE TdeCertificate; | |
END | |
GO | |
IF (SELECT is_encrypted FROM master.sys.databases WHERE [name]='K2') = 0 | |
BEGIN | |
ALTER DATABASE [K2] | |
SET ENCRYPTION ON; | |
END | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment