Join our Newsletter — 33% off our NHI Course
Home› Guides› SQL Server TDE and Always Encrypted Guide: Keys,…
Guide Data Security

SQL Server TDE and Always Encrypted Guide: Keys, Certificates and Backup Recovery

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 18 November 2026 14 min read
On this page

In SQL Server, the encryption is rarely what fails: the keys are, and a TDE certificate that was never backed up turns every encrypted backup into a file nobody can restore. This guide covers the key hierarchies behind Transparent Data Encryption (TDE) and Always Encrypted, how to back up, move and recover TDE certificates, how to run Always Encrypted keys with real role separation, and the checks that prove you can still decrypt your data on a bad day.

For the wider SQL Server control set, including logins, server roles, service accounts and audit, see the Microsoft SQL Server Security Guide. This page stays on encryption keys and recovery.

This is an independent guide from NHI Mgmt Group, based on Microsoft's public documentation as of November 2026. It is not sponsored or reviewed by Microsoft. Product features change, so confirm settings against Microsoft's current documentation.

Key takeaways

  • Back up the TDE certificate and private key the moment you enable TDE. Microsoft warns that data loss results if the certificates are no longer available, and that without the backups you cannot open the database on another server.
  • TDE encrypts at rest, not in use. It encrypts data files, log files, backups and tempdb, but not FILESTREAM data, buffer pool extension files or traffic on the wire, and anyone who can query the database sees plaintext.
  • Always Encrypted keeps keys out of the engine. The client driver encrypts and decrypts; the database stores only encrypted key values and metadata, so administrators without key store access cannot see plaintext.
  • Role separation is a choice you have to make. Microsoft recommends generating Always Encrypted keys away from the database host and separating security administrators from DBAs if the goal is to keep DBAs from the data.
  • Never drop the certificate, even after turning TDE off. Old backups still need it.
  • Test restores on a different server. A restore on the original instance proves nothing about the certificate backup.

Two features, two threat models

TDE and Always Encrypted are often listed together as "SQL Server encryption", but they protect against different people.

QuestionTransparent Data EncryptionAlways Encrypted
What is encryptedWhole database: data and log files, backups, tempdbChosen columns
Where encryption happensIn the Database Engine, at page level on write to diskIn the client driver, before data reaches the engine
Who sees plaintextAnyone with SQL permission to read the dataOnly clients with access to the column master key
Protects againstStolen data files, disks and backup filesPrivileged administrators and cloud operators reading sensitive columns
Root of trustCertificate in master or EKM asymmetric keyColumn master key in an external key store
Application changeNoneAlways Encrypted-enabled driver and parameterised queries

Many estates need both: TDE to cover files and backups broadly, and Always Encrypted for a small number of columns that administrators should never see. The two use separate keys and fail in separate ways, so plan recovery for each.

The TDE key hierarchy

Microsoft documents a chain of keys, each protecting the next.

  1. Windows Data Protection API (DPAPI) sits at the root and protects the service master key at the machine level.
  2. Service master key (SMK) protects the database master key.
  3. Database master key (DMK) in master protects certificates and asymmetric keys.
  4. TDE certificate in master, or an asymmetric key held by an Extensible Key Management (EKM) provider, protects the database encryption key.
  5. Database encryption key (DEK), a symmetric key stored in the user database, encrypts the pages.

The practical consequence is that the DEK travels with the database and its backups, but the certificate that unlocks it stays in the master database of the original server. A backup file on its own is not enough to restore. You need the certificate and its private key as well.

Enabling TDE follows four steps: create a master key in master, create a certificate protected by it, create the DEK in the user database protected by the certificate (for example with ALGORITHM = AES_256), and run ALTER DATABASE ... SET ENCRYPTION ON. On SQL Server 2019 and later the background encryption scan can be paused and resumed with SET ENCRYPTION SUSPEND and SET ENCRYPTION RESUME.

What TDE does not cover

  • System databases master, model and msdb cannot use TDE. tempdb is encrypted automatically when any user database uses TDE.
  • FILESTREAM data is not encrypted, and nor are buffer pool extension files; Microsoft points to BitLocker or EFS for those.
  • TDE does not encrypt communication channels. Use TLS for connections.
  • Replication does not carry TDE across. Enable TDE separately on distribution and subscriber databases, and note that snapshot replication can write unencrypted intermediate files.
  • Log generated before or during the change of TDE state is not encrypted, so older log content can remain in plaintext.

Microsoft also notes that an expired certificate can still be used by TDE to encrypt and decrypt. Expiry does not lock you out, but it does show up in certificate scans and audits, so record TDE certificates as an expected exception rather than rotating them in a panic.

Backing up and protecting the TDE certificate

Microsoft's instruction is direct: after you enable TDE, immediately back up the certificate and its private key. Keep the certificate even if you later disable TDE, and never drop it from master, because doing so makes the encrypted database inaccessible.

The backup statement writes two files, the certificate and the private key, and protects the private key with a password:

BACKUP CERTIFICATE TDECert TO FILE = 'TDECert.cer' WITH PRIVATE KEY (FILE = 'TDECert.pvk', ENCRYPTION BY PASSWORD = '<strong password>');

Three things must be kept together, and each is useless without the others: the certificate file, the private key file and the private key password. Microsoft states that you must retain both files to recover the certificate, and that the password used to restore must match the one used at backup. The private key password does not have to match the database master key password.

NHI Mgmt Group recommendations for storing them:

  • Store the two files away from the database server and away from the backup files they unlock. A ransomware actor who encrypts or deletes both the backups and the certificate files has taken your recovery.
  • Keep the password in a secrets manager or a sealed break-glass process, not next to the files.
  • Keep at least two copies in separate locations, and record each certificate's thumbprint, server and the databases it protects.
  • Back up again every time you create or rotate a TDE certificate. Old certificates stay in scope for as long as any backup encrypted with them is retained.

Microsoft's documentation includes a query that uses pvt_key_last_backup_date in sys.certificates to find TDE certificates that have never been backed up; a null value means no backup. Run it on every instance and alert on any null.

For general key escrow and recovery practice, see the Recovery of Cryptographic Keys and Secrets Guide.

Restoring and moving TDE databases

When you restore a TDE backup, or attach TDE data files, on another server, the certificate protecting the DEK must already be installed in that server's master database. Otherwise SQL Server cannot open the files. Microsoft's procedure is:

  1. On the destination, create a database master key in master if none exists.
  2. Recreate the certificate from the backup files: CREATE CERTIFICATE TDECert FROM FILE = 'TDECert.cer' WITH PRIVATE KEY (FILE = 'TDECert.pvk', DECRYPTION BY PASSWORD = '<same password>');
  3. Restore the backup or attach the data and log files.

The permissions involved are worth noting for privileged access reviews: creating the master key needs CONTROL DATABASE on master, creating the certificate needs CREATE CERTIFICATE on master, and encrypting a database needs CONTROL DATABASE on it plus VIEW DEFINITION on the certificate or asymmetric key.

Availability groups and log shipping

For availability groups, Microsoft says to create the master key and certificates (or the EKM asymmetric key) on all secondary replicas before creating the DEK on the primary, restoring the certificate from its backup file on each secondary. With mirroring and log shipping, both databases are encrypted and log transactions are encrypted in transit between them. A failover target that lacks the certificate cannot bring the database online, so include certificate presence in your failover readiness checks.

Operational restrictions during encryption

While initial encryption, a key change or decryption is running, you cannot drop the database or a file, take the database offline, detach it, or set it or a filegroup to read only. If any filegroup is read only, the encryption operation fails. Instant file initialisation is unavailable for new files when TDE is enabled. Schedule TDE changes as planned maintenance.

Removing TDE

Run ALTER DATABASE ... SET ENCRYPTION OFF, wait for decryption to finish, and only then drop the DEK. Keep the certificate for as long as you hold backups taken while TDE was on.

EKM and external key stores

Instead of a certificate in master, the DEK can be protected by an asymmetric key held by an EKM provider, such as a hardware security module or a cloud key service. The asymmetric key must be on the EKM provider for this to work. This moves the root of trust out of the database server: a stolen copy of master and a backup are not enough to decrypt.

It also moves the recovery dependency. The SQL Server credential used to reach the EKM provider is a non-human identity, and if it is revoked, expires or loses access, the server cannot open the DEK. Treat the EKM credential as a tier-zero secret, monitor its access, and include it in disaster recovery tests. The Azure Key Vault Security Guide covers access policy and soft delete for vault-held keys.

Always Encrypted keys and roles

Always Encrypted uses two keys. A column encryption key (CEK) encrypts data in a column. A column master key (CMK) is a key-protecting key that encrypts one or more CEKs. Microsoft says to store CMKs in a trusted key store outside the database, such as Azure Key Vault, the Windows certificate store or a hardware security module. The database stores only CMK metadata, including its location, and the encrypted CEK values; it never stores or uses keys in plaintext.

The Always Encrypted-enabled client driver encrypts parameters before sending them, rewrites queries to preserve meaning, and decrypts results. That gives the separation Microsoft describes between those who own and can view the data and those who manage it but should not see it, such as on-premises DBAs and cloud operators.

Deterministic or randomized

  • Deterministic encryption always produces the same ciphertext for the same plaintext. It supports equality lookups, joins, grouping and indexing, but patterns can reveal information, especially for low-cardinality columns such as yes or no flags.
  • Randomized encryption produces different ciphertext each time and is more secure, but without secure enclaves it does not support searching, grouping, indexing or joining.

Secure enclaves, available from SQL Server 2019 and in Azure SQL Database, let the engine process encrypted data inside a protected memory area, adding comparisons, pattern matching, sorting, indexing and in-place encryption.

Role separation

Microsoft's key management overview defines two roles. The security administrator generates CEKs and CMKs and manages the key stores, and does not need database access. The DBA manages key metadata in the database and does not need access to the keys or key store. Microsoft recommends managing keys with role separation if the goal is to stop DBAs from accessing sensitive data, and says keys should never be generated on a computer hosting the database. SQL Server Management Studio wizards combine key store and database access, so they do not support role separation; the SQL Server PowerShell cmdlets support both models.

Two permissions are central. VIEW ANY COLUMN MASTER KEY DEFINITION and VIEW ANY COLUMN ENCRYPTION KEY DEFINITION are required to select encrypted columns. In SQL Server the public role grants them by default, so administrators may need to revoke them; in Azure SQL Database they are not granted by default.

Where identity fits

In practice, the identity that holds CMK access is usually an application: a service account, managed identity or workload identity that the driver uses to unwrap CEKs from Key Vault or the certificate store. That identity can read every encrypted value the application can query. Give each application its own identity, grant it only the key operations it needs (unwrap, not delete or export), and log key access. A shared identity across applications quietly collapses the separation Always Encrypted was bought for.

Rotation and limits

Rotation means replacing a key because it is compromised or because policy requires it. Microsoft provides SSMS and PowerShell procedures for rotating Always Encrypted keys. Without enclaves, re-encrypting a column means moving data out of the database and back, which is slow for large tables; enclaves shorten this significantly. After changing an encrypted column, run sp_refresh_parameter_encryption to refresh metadata.

Plan for the limits before choosing columns: computations on randomized columns are not possible, values must be passed as parameters rather than literals, and features including SQL Server Replication, Full-Text Search, FOR JSON, FOR XML and distributed queries are not supported on encrypted columns.

Monitoring and recovery testing

  • Encryption state. Query sys.dm_database_encryption_keys; an encryption_state of 3 means the database and logs are encrypted. Alert on databases expected to be encrypted that are not.
  • Certificate backup. Alert on any TDE certificate with a null pvt_key_last_backup_date.
  • Audit changes. TDE changes are captured by SQL Server Audit under DATABASE_OBJECT_CHANGE_GROUP. Alert on SET ENCRYPTION OFF, DEK changes and certificate drops.
  • Key store access. Log every unwrap and key operation in the key store holding CMKs or EKM keys, and alert on unexpected callers.
  • Restore drill. At least quarterly, restore a TDE backup to a clean server that has never seen the certificate, using only the escrowed files and password. Time it, and record the result as evidence. The Database Backup Security Guide covers drill design.

Common failure patterns

  • TDE enabled with no certificate backup, discovered only when the server is lost.
  • Certificate files stored with the backups on the same share, so one compromise removes both.
  • Password lost while the certificate and key files survive, leaving files that cannot be loaded.
  • Certificate dropped after disabling TDE, making older backups unrecoverable.
  • Availability group secondaries without the certificate, so failover fails when it is needed.
  • Treating TDE as protection from administrators, when anyone with read permission still sees plaintext.
  • Always Encrypted keys generated on the database host or through SSMS by DBAs, removing role separation.
  • Default public grants left on key definition views in SQL Server.
  • One shared service identity with CMK access across many applications.

Practitioner checklist

  • Back up every TDE certificate and private key immediately after creation, with the password stored separately.
  • Keep two escrowed copies away from both the database server and the backup storage.
  • Alert on null pvt_key_last_backup_date for TDE certificates.
  • Never drop a TDE certificate while any backup encrypted with it is retained.
  • Install certificates on all availability group secondaries and DR servers before encryption.
  • Run a quarterly restore of a TDE backup to a clean server using only escrowed material.
  • Use TLS for connections; TDE does not encrypt traffic.
  • Store Always Encrypted CMKs in an external key store and generate keys off the database host.
  • Decide on role separation explicitly and use PowerShell where it is required.
  • Give each application its own identity for CMK access with least privilege, and log key use.
  • Audit TDE state changes and key operations.

Standards and references

Related NHI Mgmt Group resources: Microsoft SQL Server Security Guide · Cryptographic Key Management Guide · Database Backup Security Guide · How to audit SQL Server service accounts and logins

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.