Dynamic Data Masking hides sensitive column data from non-privileged users by automatically replacing it with obfuscated values at query time.
Dynamic Data Masking (DDM) hides sensitive column values from non-privileged users in real time, reducing the need to duplicate data or build custom views. It is ideal for showing production data to support teams or analysts without exposing PII.
Define masking when creating the table by adding ‘MASKED WITH (FUNCTION = 'mask_function)’ to the column definition. SQL Server supports default(), email(), partial(), and random() functions.
Use ALTER TABLE … ALTER COLUMN … ADD MASKED WITH (FUNCTION = 'mask_function) to retrofit masking without rewriting the table.
Grant the UNMASK permission to a login or role. Users with UNMASK always see the real values; others receive the masked output.
Mask only columns that hold sensitive data, combine DDM with row-level security, and always test masking with different user roles to verify expected visibility.
default(), email(), random(start,end), and partial(prefix, padding, suffix) are built-in.
DDM is applied on the result set, so its overhead is minimal and usually unnoticeable.
DDM and Always Encrypted cannot coexist on the same column. Use a separate encrypted copy or cell-level encryption if both are needed.