CREATE DATABASE ENCRYPTION KEY
WITH ALGORITHM = AES_256
ENCRYPTION BY SERVER CERTIFICATE MyServerCert;
ALTER DATABASE MyDatabase SET ENCRYPTION ON;
Topics
43
Aggregate Functions & GROUP BY
Always On Availability Groups
Backup & Recovery
Change Data Capture (CDC)
Columnstore Indexes
Common Table Expressions (CTEs)
Constraints (Primary Key, Foreign Key, Check & Unique)
Cursors
Data Types & Schema Design
Deadlocks
Dynamic Data Masking
Dynamic SQL
Error Handling with TRY CATCH
Full Text Search
Hash Indexes & Hash Join Operations
Indexes
In-Memory OLTP (Memory-Optimized Tables)
Isolation & Locking
Joins
JSON Support in SQL Server
Linked Servers
Merge Statement (Upsert)
Normalization
Partitioning
Pivoting & Unpivoting Data
Query Optimization & Plans
Query Store
Replication
SQL Server Agent & Job Scheduling
SQL Server Architecture & Editions
SQL Server Profiler & Extended Events
SQL Server Security & Permissions
Stored Procedures & Functions
Subqueries
Temporary Tables & Table Variables
Transactions & ACID
Transparent Data Encryption
Triggers
T-SQL Fundamentals & Syntax
User Defined Functions
Views
Window Functions
XML Data Type & Querying
Transparent Data Encryption
7 questions found
Transparent Data Encryption, often called TDE, encrypts an entire database's data and log files at rest on disk, protecting against the scenario where someone gains physical access to the actual database files or backup files and tries to read them directly, without requiring any changes to the application querying the database normally.
Real-world example
A healthcare company enables Transparent Data Encryption on their patient records database, ensuring that even if a backup file were somehow stolen, the data within it would remain completely unreadable without the proper encryption keys.
Backup & Recovery;Dynamic Data Masking
What is the difference between what Transparent Data Encryption protects against compared to Dynamic Data Masking?
BeginnerTransparent Data Encryption protects data at rest, meaning the physical files on disk, guarding against theft of the actual database or backup files, while Dynamic Data Masking protects against unauthorized viewing of sensitive data by legitimate users who are already properly querying the database, meaning the two features address entirely different security concerns and are often used together.
-- TDE protects the physical files
ALTER DATABASE MyDatabase SET ENCRYPTION ON;
-- Dynamic Data Masking protects what authorized query users see
ALTER TABLE Customers ALTER COLUMN Email ADD MASKED WITH (FUNCTION = 'email()');
Real-world example
A financial company uses Transparent Data Encryption to protect their database files from being stolen and read directly, while separately using Dynamic Data Masking to limit what sensitive data regular employees can see when they run normal queries.
SQL Server Security & Permissions;Backup & Recovery
What is the hierarchy of encryption keys and certificates involved in setting up Transparent Data Encryption?
IntermediateTDE relies on a hierarchy starting with a service master key at the server level, which protects a database master key, which in turn protects a server certificate, and finally that certificate is used to encrypt the database encryption key specific to each individual database that has TDE enabled, creating a chain of protection from the top level server security down to the actual data.
-- Setting up the key hierarchy from the top down
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'StrongPassword123!';
CREATE CERTIFICATE MyServerCert WITH SUBJECT = 'TDE Certificate';
CREATE DATABASE ENCRYPTION KEY WITH ALGORITHM = AES_256 ENCRYPTION BY SERVER CERTIFICATE MyServerCert;
Real-world example
A database administrator carefully follows the correct order for setting up the encryption key hierarchy, starting with the master key, then the certificate, before finally creating the database encryption key needed to enable TDE.
Backup & Recovery;SQL Server Security & Permissions
Why is it critically important to back up the certificate used for Transparent Data Encryption, and what happens if it is lost?
IntermediateIf the certificate used to protect a TDE encrypted database is lost without a proper backup, you will be permanently unable to restore that database's backups or attach its data files on a different server, since the certificate is required to decrypt the database encryption key, making a certificate backup just as important as the actual database backups themselves.
BACKUP CERTIFICATE MyServerCert
TO FILE = 'C:\Backups\MyServerCert.cer'
WITH PRIVATE KEY (
FILE = 'C:\Backups\MyServerCert.pvk',
ENCRYPTION BY PASSWORD = 'StrongPassword123!'
);
Real-world example
A company that enabled TDE without properly backing up their certificate discovers, after a hardware failure, that their database backups are completely unusable, learning a costly lesson about the absolute necessity of also backing up TDE certificates.
Backup & Recovery;SQL Server Security & Permissions
What is the performance overhead of Transparent Data Encryption, and how does it compare across different SQL Server versions?
AdvancedTDE introduces a small amount of CPU overhead since data must be encrypted before being written to disk and decrypted when read back, though modern SQL Server versions have significantly optimized this process, and the overhead is generally considered acceptable for most workloads, though it should still be measured and tested specifically for particularly performance sensitive applications before enabling it broadly.
-- Measure performance before and after enabling TDE
-- using a representative workload test
SET STATISTICS TIME ON;
SELECT COUNT(*) FROM LargeTable;
Real-world example
A performance sensitive trading platform carefully benchmarks their most critical queries both before and after enabling TDE, confirming the overhead is negligible for their specific workload before rolling it out to production.
Query Optimization & Plans;SQL Server Architecture & Editions
How would you migrate a TDE encrypted database to a new server, and what specific steps are required to ensure the migration succeeds?
AdvancedYou would first back up the certificate and its private key from the original server, restore that certificate onto the new destination server, ensure the database master key is properly set up on the new server as well, and only then restore the actual database backup, since attempting to restore a TDE encrypted database without first properly setting up the matching certificate on the destination server will fail.
-- On the new server, restore the certificate first
CREATE CERTIFICATE MyServerCert
FROM FILE = 'C:\Backups\MyServerCert.cer'
WITH PRIVATE KEY (FILE = 'C:\Backups\MyServerCert.pvk', DECRYPTION BY PASSWORD = 'StrongPassword123!');
-- Then restore the database
RESTORE DATABASE MyDatabase FROM DISK = 'C:\Backups\MyDatabase.bak';
Real-world example
A company migrating their encrypted database to a new server carefully restores the TDE certificate first, confirming it matches the original before attempting to restore the actual encrypted database backup, avoiding a failed migration.
Backup & Recovery;Deployment
How do you check whether Transparent Data Encryption is currently enabled on a specific database?
IntermediateYou can query the sys.dm_database_encryption_keys dynamic management view, which shows the encryption state for every database on the server, letting you confirm whether TDE is actually active and functioning correctly, which is a useful verification step after initially enabling it or during a routine security audit.
SELECT DB_NAME(database_id) AS DatabaseName, encryption_state, encryption_state_desc
FROM sys.dm_database_encryption_keys;
Real-world example
A security auditor runs a query against sys.dm_database_encryption_keys across all databases on a server, quickly confirming which databases have TDE properly enabled and which ones might still need it applied as part of a compliance review.
SQL Server Security & Permissions;Backup & Recovery