the Database Master key always has an symmetric_key_id = 101, i read someplace, so my scripts all use that:
IF NOT EXISTS (SELECT * FROM sys.symmetric_keys WHERE symmetric_key_id = 101)
BEGIN
PRINT 'Creating Database Master Key'
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'NotTheRealPassword'
END
ELSE
BEGIN
PRINT 'Database Master Key Alread Exists'
END
--drop certificate MyDemoDataSecurityCertificate?
--create our certificate.
IF NOT EXISTS(SELECT *
FROM sys.certificates
WHERE name = 'MyDemoDataSecurityCertificate')
BEGIN
CREATE CERTIFICATE MyDemoDataSecurityCertificate WITH SUBJECT = 'MyDemo DataSecurity Certificate', EXPIRY_DATE = '12/31/2024'
PRINT 'MyDemoDataSecurityCertificate Created'
END
ELSE
BEGIN
PRINT 'MyDemoDataSecurityCertificate Already Exists.'
END
Lowell