ALTER DATABASE … SET ENCRYPTION ON activates Transparent Data Encryption (TDE) to protect data at rest.
Encryption shields data files and backups from unauthorized reads. Even if someone copies the .mdf
or backup file, the data remains unreadable without the key hierarchy, meeting compliance rules like PCI-DSS and GDPR.
Run SQL Server 2019+ Enterprise or Azure SQL DB. You need CONTROL SERVER permission, a strong password for the master key, and disk space for encrypted tempdb growth.
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'P@ssw0rd!Strong';
CREATE CERTIFICATE TDE_ServerCert WITH SUBJECT = 'TDE Cert';
USE EcommerceDB; CREATE DATABASE ENCRYPTION KEY WITH ALGORITHM = AES_256 ENCRYPTION BY SERVER CERTIFICATE TDE_ServerCert;
ALTER DATABASE EcommerceDB SET ENCRYPTION ON;
Query sys.dm_database_encryption_keys
or sys.databases
. A status of 3 or 2 means encryption is active or in progress.
Disable with ALTER DATABASE EcommerceDB SET ENCRYPTION OFF;
but note that decryption is slow and blocks backups until complete.
Back up the server certificate and private key immediately: BACKUP CERTIFICATE TDE_ServerCert TO FILE = 'C:\backup\TDE_ServerCert.cer' WITH PRIVATE KEY (FILE = 'C:\backup\TDE_ServerCert.pvk', ENCRYPTION BY PASSWORD = 'CertBackUp@123');
Store backups off-site.
Minimal impact (<5%) because encryption occurs at the page level and is hardware-accelerated on modern CPUs.
Yes. When any user database is encrypted, SQL Server encrypts tempdb
to prevent data leakage.
Yes. Restore the certificate on each replica, then turn encryption on. The log stream is automatically encrypted.