Tag: Dynamic Data Masking

Design and implement Dynamic Data Masking (DDM) (DP-800 Exam Prep)

This post is a part of the DP-800: Developing AI-Enabled Database Solutions Exam Prep Hub.
This topic falls under these sections:
Secure, optimize, and deploy database solutions (35–40%)
   --> Implement data security and compliance
      --> Design and implement Dynamic Data Masking


Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.

What is Dynamic Data Masking?

Dynamic Data Masking (DDM) is a SQL Server and Azure SQL feature that limits the exposure of sensitive data by masking the results returned to non-privileged users without modifying the actual data stored in the database.

Unlike encryption, DDM does not change or encrypt the stored data. Instead, SQL Server dynamically replaces sensitive values with masked values when queries are executed by users who do not have permission to view the original data.

For example, the database may contain:

CustomerNameSSNEmail
John Smith123-45-6789john@email.com

A privileged user sees:

CustomerNameSSNEmail
John Smith123-45-6789john@email.com

A non-privileged user may see:

CustomerNameSSNEmail
John SmithXXX-XX-6789jXXX@XXXX.com

The underlying data never changes.


Why Use Dynamic Data Masking?

Organizations frequently store sensitive information such as:

  • Personally Identifiable Information (PII)
  • Social Security Numbers
  • Credit card numbers
  • Email addresses
  • Phone numbers
  • Employee salaries
  • Medical information

Not every user who queries the database should have unrestricted access to these values.

DDM allows developers to:

  • Reduce accidental data exposure
  • Protect sensitive fields
  • Simplify application development
  • Support compliance initiatives
  • Allow customer support personnel to work with realistic-looking data

How Dynamic Data Masking Works

When a user executes a query:

  1. SQL Server checks whether the user has permission to view unmasked data.
  2. If the user has the UNMASK permission, actual values are returned.
  3. Otherwise, SQL Server substitutes masked values before sending the results.

The database itself remains unchanged.


Dynamic Data Masking Architecture

Database
├── Actual Data
│ 987-65-4321
├── User A
│ Has UNMASK permission
│ Result:
│ 987-65-4321
└── User B
No UNMASK permission
Result:
XXX-XX-4321

Benefits of Dynamic Data Masking

DDM provides several important advantages.

Easy to Implement

Masking is configured using T-SQL without requiring application changes.


No Data Duplication

The original data remains stored only once.


Transparent to Applications

Applications continue issuing the same queries.

No application code changes are required.


Supports Least Privilege

Users receive only the information they need.


Helps Meet Compliance Requirements

Although DDM is not encryption, it helps organizations reduce unnecessary exposure of sensitive information.


Dynamic Data Masking vs Encryption

Dynamic Data MaskingEncryption
Masks query resultsEncrypts stored data
Data remains unchangedData stored encrypted
Protects against accidental viewingProtects against data theft
Transparent to applicationsMay require encryption keys
Does not secure backupsProtects stored data

Microsoft expects candidates to understand that DDM is not a replacement for encryption technologies such as Always Encrypted or Transparent Data Encryption (TDE).


Supported Masking Functions

SQL Server supports several built-in masking functions.


Default Mask

Masks data according to its data type.

Example:

Original:

John Smith

Masked:

XXXX

Syntax:

MASKED WITH (FUNCTION = 'default()')

Email Mask

Designed specifically for email addresses.

Original:

john.smith@email.com

Masked:

jXXX@XXXX.com

Syntax:

MASKED WITH (FUNCTION = 'email()')

Partial Mask

Reveals part of a string while masking the remainder.

Example:

Original:

555-123-4567

Masked:

XXX-XXX-4567

Syntax:

MASKED WITH
(
FUNCTION='partial(prefix,padding,suffix)'
)

Example:

MASKED WITH
(
FUNCTION='partial(0,"XXX-XXX-",4)'
)

Random Mask

Returns a random value within a specified numeric range.

Example:

Original Salary

85000

Masked

43782

Syntax

MASKED WITH
(
FUNCTION='random(1,100000)'
)

Useful when exact values should never be exposed.


Creating a Masked Column

Example:

CREATE TABLE Customers
(
CustomerID INT,
Name NVARCHAR(100),
Email NVARCHAR(200)
MASKED WITH (FUNCTION='email()'),
SSN CHAR(11)
MASKED WITH
(
FUNCTION='partial(0,"XXX-XX-",4)'
)
);

Adding a Mask to an Existing Column

ALTER TABLE Customers
ALTER COLUMN Email
ADD MASKED
WITH (FUNCTION='email()');

Removing a Mask

ALTER TABLE Customers
ALTER COLUMN Email
DROP MASKED;

Granting UNMASK Permission

Privileged users may view actual values.

GRANT UNMASK TO HRManager;

Revoking Permission

REVOKE UNMASK FROM HRManager;

Viewing Mask Definitions

View masking metadata.

SELECT *
FROM sys.masked_columns;

Useful during administration and auditing.


DDM with Azure SQL Database

Dynamic Data Masking is fully supported in:

  • Azure SQL Database
  • Azure SQL Managed Instance
  • SQL Server

Azure SQL also provides portal-based configuration through the Azure Portal.

Developers can create masks without writing T-SQL.


Limitations of Dynamic Data Masking

Candidates should understand these limitations.

It Is Not Encryption

Anyone with sufficient permissions can retrieve actual values.


Database Administrators Can View Data

Members of powerful administrative roles can bypass masking.


Cannot Stop Inference Attacks

Users may infer values through repeated queries.


Not Intended for High-Security Scenarios

Highly confidential data should use:

  • Always Encrypted
  • Transparent Data Encryption
  • Row-Level Security
  • Proper access control

Expressions Return Masked Values

If a masked column is used in expressions, the expression also returns masked results for users without UNMASK permission.


Best Practices

Mask Only Sensitive Columns

Avoid unnecessary masking.


Combine with Other Security Features

Use together with:

  • Always Encrypted
  • Row-Level Security
  • Transparent Data Encryption
  • Microsoft Entra authentication
  • Least privilege access

Grant UNMASK Sparingly

Only trusted users should receive this permission.


Test Using Non-Privileged Accounts

Always verify what ordinary users actually see.


Audit Sensitive Access

Monitor who receives UNMASK permissions.


Dynamic Data Masking vs Row-Level Security

Dynamic Data MaskingRow-Level Security
Masks valuesFilters rows
User sees all rowsUser sees only authorized rows
Protects columnsProtects records
Works with SELECT resultsControls data visibility
Often used with RLSOften combined with DDM

DP-800 Exam Tips

Candidates should be able to:

  • Explain what Dynamic Data Masking is.
  • Differentiate masking from encryption.
  • Identify supported masking functions.
  • Create masked columns using CREATE TABLE and ALTER TABLE.
  • Grant and revoke the UNMASK permission.
  • Understand when DDM is appropriate.
  • Recognize DDM limitations.
  • Choose DDM versus Always Encrypted, TDE, or Row-Level Security based on the security requirement.
  • Understand that DDM protects against accidental exposure, not malicious users with elevated privileges.

Practice Exam Questions

Question 1

A company wants customer support representatives to view only partially masked Social Security numbers while allowing HR staff to view the full values.

Which SQL Server feature best meets this requirement?

A. Transparent Data Encryption

B. Dynamic Data Masking

C. Always Encrypted

D. Data Compression

Answer: B

Explanation: Dynamic Data Masking displays masked values to unauthorized users while allowing authorized users with the appropriate permissions to see the original data.


Question 2

Which statement about Dynamic Data Masking is true?

A. It encrypts data stored on disk.

B. It permanently changes stored values.

C. It masks query results for users without UNMASK permission.

D. It replaces encryption.

Answer: C

Explanation: Dynamic Data Masking only alters the data presented in query results. The stored values remain unchanged.


Question 3

Which masking function is specifically designed for email addresses?

A. partial()

B. random()

C. default()

D. email()

Answer: D

Explanation: The email() masking function preserves the general format of an email address while obscuring most of the information.


Question 4

Which statement best describes the partial() masking function?

A. It encrypts selected characters.

B. It returns random values.

C. It permanently replaces data.

D. It reveals specified prefix and suffix characters while masking the middle.

Answer: D

Explanation: The partial() function exposes configurable leading and trailing characters while masking the remaining portion of the value.


Question 5

Which permission allows a user to view unmasked data?

A. SELECT

B. CONTROL

C. UNMASK

D. VIEW DEFINITION

Answer: C

Explanation: Users granted the UNMASK permission can view the original values instead of the masked representations.


Question 6

Which system catalog view displays information about masked columns?

A. sys.columns

B. sys.masked_columns

C. sys.tables

D. sys.database_permissions

Answer: B

Explanation: The sys.masked_columns catalog view contains metadata about all columns configured with Dynamic Data Masking.


Question 7

A database administrator wants to protect highly confidential financial information from administrators who manage the database server.

Which technology should be preferred over Dynamic Data Masking?

A. Always Encrypted

B. Dynamic Data Masking

C. Partial masking

D. Random masking

Answer: A

Explanation: Always Encrypted ensures that sensitive data remains encrypted even from database administrators because encryption and decryption occur on the client side.


Question 8

Which statement about Dynamic Data Masking and application code is generally correct?

A. Applications must always be rewritten.

B. DDM requires client-side decryption.

C. Existing queries usually continue to work without modification.

D. Applications cannot access masked tables.

Answer: C

Explanation: Dynamic Data Masking is transparent to most applications, allowing existing queries to function normally while returning masked data when appropriate.


Question 9

A developer executes the following statement:

GRANT UNMASK TO SalesManager;

What is the effect?

A. The SalesManager can modify masked columns.

B. The SalesManager can bypass row-level security.

C. The SalesManager can view original values in masked columns, provided they also have permission to access the data.

D. All users inherit the UNMASK permission.

Answer: C

Explanation: The UNMASK permission allows a user to see unmasked values but does not grant access to data that the user is otherwise unauthorized to read.


Question 10

Which security strategy provides the strongest protection for sensitive database columns?

A. Use only Dynamic Data Masking.

B. Use only Row-Level Security.

C. Use only Transparent Data Encryption.

D. Combine Dynamic Data Masking with encryption, least-privilege access, and other SQL Server security features.

Answer: D

Explanation: Dynamic Data Masking is most effective as part of a layered security strategy that also includes encryption, access controls, auditing, and other SQL Server security features.


Go to the DP-800 Exam Prep Hub main page

Implement dynamic data masking (DP-700 Exam Prep)

This post is a part of the DP-700: Implementing Data Engineering Solutions Using Microsoft Fabric Exam Prep Hub.
This topic falls under these sections:
Implement and manage an analytics solution (30–35%)
   --> Configure security and governance
      --> Implement dynamic data masking


Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 2 practice tests with 60 questions each available from the hub's main page below the exam topics section.

Introduction

Protecting sensitive data is a critical responsibility for data engineers. Organizations routinely store confidential information such as:

  • Personally Identifiable Information (PII)
  • Social Security numbers
  • Credit card information
  • Email addresses
  • Phone numbers
  • Employee salaries
  • Customer account details

While some users require access to this information, many others only need access to the surrounding business data. Granting unrestricted visibility to sensitive values can increase security risks and create compliance concerns.

Dynamic Data Masking (DDM) is a security feature that limits the exposure of sensitive data by masking values for non-privileged users while allowing authorized users to see the original values.

For the DP-700 exam, it is important to understand how Dynamic Data Masking works, its use cases, limitations, and how it differs from other security mechanisms such as Row-Level Security (RLS), Column-Level Security (CLS), and encryption.


What Is Dynamic Data Masking?

Dynamic Data Masking is a security feature that obscures sensitive data at query time.

The actual data remains unchanged in storage.

Instead, unauthorized users see a masked version of the data.

Example:

Actual data:

CustomerNameEmail
John Smithjohn.smith@contoso.com

Masked view:

CustomerNameEmail
John SmithjXXXXXXX@XXXX.com

The original data still exists in the database.

Only the displayed results are modified.


Why Use Dynamic Data Masking?

Organizations often need to:

  • Protect confidential information
  • Limit exposure of sensitive fields
  • Support regulatory compliance
  • Reduce accidental data disclosure
  • Allow broader access to datasets without exposing confidential values

Dynamic Data Masking provides a simple way to accomplish these goals.


How Dynamic Data Masking Works

The masking process occurs during query execution.

User Query
Security Evaluation
Masking Applied
Results Returned

Authorized users:

john.smith@contoso.com

Unauthorized users:

jXXXXXXX@XXXX.com

The underlying stored value never changes.


Common Dynamic Data Masking Use Cases

Customer Contact Information

Sensitive fields:

  • Email addresses
  • Phone numbers
  • Mailing addresses

Example:

Actual:
john.smith@contoso.com
Masked:
jXXXXXXX@XXXX.com

Employee Information

Sensitive fields:

  • Salary
  • Bonus information
  • Tax identifiers

Example:

Actual:
$120,000
Masked:
$XXXXXX

Financial Information

Sensitive fields:

  • Credit card numbers
  • Bank account numbers
  • Account balances

Example:

Actual:
4321-5678-9876-1234
Masked:
XXXX-XXXX-XXXX-1234

Types of Data That Can Be Masked

Common candidates include:

  • Email addresses
  • Phone numbers
  • National identification numbers
  • Credit card numbers
  • Salary data
  • Medical information
  • Customer account information

Generally, highly sensitive columns are good candidates for masking.


Dynamic Data Masking vs Encryption

This distinction is frequently tested on certification exams.

Dynamic Data MaskingEncryption
Protects displayed resultsProtects stored data
Data remains visible to privileged usersData is encrypted at rest or in transit
User-facing security featureStorage and transport security feature
Does not alter stored valuesChanges stored representation

Example

Dynamic Data Masking:

Stored:
123-45-6789
Displayed:
XXX-XX-6789

Encryption:

Stored:
A7F4D93C12...

Dynamic Data Masking vs Row-Level Security

These concepts are often confused.

Dynamic Data MaskingRow-Level Security
Hides data valuesFilters rows
Same rows visibleDifferent rows visible
Column-focusedRow-focused
Data remains visible in masked formRows may be completely hidden

Example:

RLS:

East Region Manager
→ East Region Rows Only

DDM:

All Rows Visible
→ Sensitive Values Masked

Dynamic Data Masking vs Column-Level Security

Another important distinction.

Dynamic Data MaskingColumn-Level Security
Shows masked valuesHides column entirely
User sees partial dataUser cannot access column
More flexible visibilityMore restrictive security

Example:

DDM:

Salary
XXXXXX

CLS:

Salary Column
Not Visible

Dynamic Data Masking vs Object-Level Security

Dynamic Data MaskingObject-Level Security
Masks data valuesHides objects
User accesses tableTable may be hidden
Granular data visibilityObject visibility control

Example:

DDM:

Salary = XXXXX

OLS:

Payroll Table Hidden

Benefits of Dynamic Data Masking

Simplified Security

Protects sensitive values without redesigning datasets.


Reduced Data Exposure

Users only see the information necessary for their role.


Regulatory Support

Can help support compliance initiatives involving:

  • GDPR
  • HIPAA
  • PCI DSS
  • Internal governance policies

Easier Data Sharing

Organizations can provide broader dataset access while reducing risk.


Limitations of Dynamic Data Masking

For the DP-700 exam, understanding limitations is important.

Dynamic Data Masking:

Does NOT Encrypt Data

Data remains stored in its original form.


Does NOT Replace Access Controls

Users still require appropriate permissions.


Does NOT Replace RLS

Rows remain visible.


Does NOT Replace CLS

Columns remain accessible.


Is Not a Complete Security Solution

DDM should be combined with other security mechanisms.


Layered Security Approach

Organizations commonly combine:

Workspace Security
Item Security
Row-Level Security
Column-Level Security
Dynamic Data Masking
Encryption

Each layer provides additional protection.


Common DP-700 Exam Scenarios

Scenario 1

Requirement:

Customer service representatives should view customer records but not full credit card numbers.

Solution:

Implement Dynamic Data Masking.


Scenario 2

Requirement:

Managers should only see employees within their region.

Solution:

Implement Row-Level Security.


Scenario 3

Requirement:

Payroll data should be completely hidden from analysts.

Solution:

Implement Object-Level Security or Column-Level Security.


Scenario 4

Requirement:

Protect sensitive data stored on disk.

Solution:

Use encryption rather than Dynamic Data Masking.


Best Practices

Mask Sensitive Columns

Focus on:

  • PII
  • Financial data
  • Healthcare information
  • Confidential business information

Combine DDM with Other Controls

Use:

  • Workspace permissions
  • Item permissions
  • RLS
  • CLS
  • OLS

for comprehensive protection.


Follow Least Privilege

Limit access to unmasked data.


Regularly Review Security Policies

Verify masking requirements align with governance policies.


Protect Production Data

Apply masking wherever sensitive data exposure could occur.


DP-700 Exam Focus Areas

You should understand:

✓ Dynamic Data Masking concepts

✓ How masking works

✓ Common masking scenarios

✓ Sensitive data protection

✓ Dynamic Data Masking vs Encryption

✓ Dynamic Data Masking vs RLS

✓ Dynamic Data Masking vs CLS

✓ Dynamic Data Masking vs OLS

✓ Security best practices

✓ Layered security approaches


Practice Exam Questions

Question 1

What is the primary purpose of Dynamic Data Masking?

A. Encrypt stored data

B. Restrict workspace access

C. Filter rows returned by a query

D. Hide sensitive data values from unauthorized users

Answer: D

Explanation

Dynamic Data Masking obscures sensitive data values in query results while leaving the underlying stored data unchanged.


Question 2

Which statement about Dynamic Data Masking is true?

A. It permanently modifies stored data.

B. It encrypts data at rest.

C. It masks data at query time for unauthorized users.

D. It removes sensitive columns.

Answer: C

Explanation

DDM operates at query time and displays masked values to users who do not have permission to view the actual data.


Question 3

A company wants customer service agents to view customer records while masking credit card numbers.

Which feature should be implemented?

A. Dynamic Data Masking

B. Row-Level Security

C. Deployment Rules

D. Workspace Viewer Role

Answer: A

Explanation

DDM allows users to view records while hiding sensitive portions of specific data fields.


Question 4

What is the primary difference between Dynamic Data Masking and Row-Level Security?

A. DDM encrypts data while RLS does not.

B. DDM controls workspace permissions while RLS controls item permissions.

C. DDM hides columns while RLS hides tables.

D. DDM masks values while RLS filters rows.

Answer: D

Explanation

RLS determines which rows are visible, while DDM determines how sensitive values are displayed.


Question 5

Which security feature completely hides a column from users?

A. Dynamic Data Masking

B. Column-Level Security

C. Row-Level Security

D. Encryption

Answer: B

Explanation

Column-Level Security removes access to the column entirely, whereas DDM displays masked values.


Question 6

A company needs to protect sensitive data stored on disk.

Which technology should be used?

A. Dynamic Data Masking

B. Build Permission

C. Encryption

D. Row-Level Security

Answer: C

Explanation

Encryption protects stored data, while DDM only affects how data is displayed.


Question 7

Which type of data is commonly protected using Dynamic Data Masking?

A. Email addresses

B. Credit card numbers

C. Social Security numbers

D. All of the above

Answer: D

Explanation

DDM is commonly used to protect various forms of sensitive personal and financial information.


Question 8

A user can access a salary column but sees masked values instead of actual salaries.

Which security feature is being used?

A. Row-Level Security

B. Dynamic Data Masking

C. Object-Level Security

D. Folder-Level Security

Answer: B

Explanation

DDM allows access to the column while masking sensitive values.


Question 9

Which statement accurately describes Dynamic Data Masking?

A. It replaces all other security controls.

B. It prevents users from accessing tables.

C. It should be combined with other security mechanisms.

D. It filters data based on user region.

Answer: C

Explanation

DDM is one layer of security and should be used alongside permissions, RLS, CLS, and encryption.


Question 10

A company wants users to see the last four digits of credit card numbers while masking the rest.

Which solution is most appropriate?

A. Object-Level Security

B. Workspace-Level Security

C. Encryption

D. Dynamic Data Masking

Answer: D

Explanation

Dynamic Data Masking can reveal portions of sensitive values while masking the remaining characters.


Exam Tip

One of the most common DP-700 exam traps is confusing Dynamic Data Masking with other security technologies.

Remember:

RequirementSolution
Hide sensitive valuesDynamic Data Masking
Filter rowsRow-Level Security
Hide columnsColumn-Level Security
Hide tables or measuresObject-Level Security
Protect stored dataEncryption

If users should still be able to access a column but only see a masked version of its contents, Dynamic Data Masking is usually the correct answer.


Go to the DP-700 Exam Prep Hub main page.