Skill 2.1.2

Design and implement Dynamic Data Masking

Key Concepts

A mask is added to a column with MASKED WITH (FUNCTION = '...'). The default() function shows XXXX for strings, 0 for numbers and 01-01-1900 for dates; email() shows the first letter and a constant domain; random(start, end) replaces numbers with a random value; and partial(prefix, padding, suffix) keeps chosen characters, such as the last four digits of a card number. Users with UNMASK see real values; in Azure SQL Database and SQL Server 2022 and later, UNMASK can be granted at database, schema, table or column level, and ALTER ANY MASK manages masks.

DDM is not encryption and is not a security boundary: data is stored in plaintext, privileged users always see it, and a user who can run ad hoc queries can infer values with predicates such as WHERE Salary > 100000. It suits limiting exposure in applications and support tools, usually combined with RLS, permissions and auditing. Copying masked data with SELECT INTO or INSERT stores the masked values.