![]() |
VOOZH | about |
SQL Data Encryption is used to protect sensitive database information from unauthorized access by converting it into an unreadable format. It helps in:
The SQL database supports various encryption methods, each with its unique characteristics and applications. Modern SQL databases support various encryption techniques, each catering to specific use cases and different levels of protection.
This section explores the various methods of securing data in SQL databases, including Transparent Data Encryption (TDE) and Column-Level Encryption (CLE). Each type is explained with its use cases, implementation steps, and benefits.
Transparent Data Encryption (TDE) encrypts the entire database, including the data and log files stored at rest. This process runs seamlessly in the background without affecting user applications.
Letβs implement TDE using the following steps. First, we will set up a demo table for better understanding:
CREATE TABLE Student (
StudentID INT PRIMARY KEY,
StudentName VARCHAR(30) NOT NULL,
RollNumber VARCHAR(10) NOT NULL
);
INSERT INTO Student VALUES
(1, 'John', '1234'),
(2, 'Michael', '4321'),
(3, 'Emily', '4554'),
(4, 'Sophia', '7896');
Output:
π Screenshot-2026-02-11-1140471. Create a Database Master Key
The master key secures the encryption hierarchy. Use the following command and choose the password of your choice
USE dba;
Go
Create MASTER KEY ENCRYPTION BY PASSWORD = "ABC@123"
Go
2. Create a Certificate
A certificate is used to protect the encryption keys.
USE dba;
Go
CREATE CERTIFICATE TDE_Certificate
WITH SUBJECT = 'Certificate for TDE'
Go
3. Create an Encryption Key
Define the database encryption key using a specific algorithm:
USE dba
GO
CREATE DATABASE ENCRYPTION KEY
WITH ALGORITHM = AES_256
ENCRYPTION BY SERVER CERTIFICATE TDE_Certificate
4.Enable Encryption
Configure the database to enable encryption using the below command
ALTER DATABASE dba
SET ENCRYPTION ON
Output
This method of encryption involves encrypting specific columns within a table rather than the whole table or the database. This method allows organizations to selectively secure their data.
In order to implement the encryption we are creating the same table Student we used for TDE for better understanding.
CREATE TABLE Student (
StudentID INT PRIMARY KEY,
StudentName VARCHAR(30) NOT NULL,
RollNumber VARCHAR(10) NOT NULL
);
INSERT INTO Student VALUES
(10, 'James', '1234'),
(20, 'Olivia', '4321'),
(30, 'William', '4554'),
(40, 'Emma', '7896');
Output:
π Screenshot-2026-02-11-120602USE Student;
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD = '123@4321';
USE Student;
GO
CREATE CERTIFICATE Certificate_test WITH SUBJECT = 'Protect my data';
GO
CREATE SYMMETRIC KEY SymKey_test WITH ALGORITHM = AES_256 ENCRYPTION BY CERTIFICATE Certificate_test;ALTER TABLE Student
ADD RollNumber_encrypt varbinary(MAX)
Output
The RollNumber_Encrypted column will now contain encrypted values, rendering them unreadable to unauthorized users.