Migrate to Innovate Summit:
Learn how migrating and modernizing to Azure can boost your business's performance, resilience, and security, enabling you to fully embrace AI.Register now
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Azure SQL Database, SQL database in Microsoft Fabric, Azure SQL Managed Instance, and Azure Synapse Analytics support dynamic data masking (DDM). Dynamic data masking limits sensitive data exposure by masking it to nonprivileged users.
Dynamic data masking helps prevent unauthorized access to sensitive data by enabling customers to designate how much of the sensitive data to reveal with minimal effect on the application layer. It's a policy-based security feature that hides the sensitive data in the result set of a query over designated database fields, while the data in the database isn't changed.
For example, a service representative at a call center might identify a caller by confirming several characters of their email address, but the complete email address shouldn't be revealed to the service representative. A masking rule can be defined that masks all the email address in the result set of any query. As another example, an appropriate data mask can be defined to protect personal data, so that a developer can query production environments for troubleshooting purposes without violating compliance regulations.
Dynamic data masking basics
For Azure SQL Database, you set up a dynamic data masking policy in the Azure portal by selecting the Dynamic Data Masking pane under Security in your SQL Database configuration pane.
SQL users excluded from masking: A set of SQL users, which can include identities from Microsoft Entra ID (formerly Azure Active Directory), that get unmasked data in the SQL query results. Users with administrative rights like server admin, Microsoft Entra admin, and db_owner role can view the original data without any mask. (Note: It also applies to sysadmin role in SQL Server)
Masking rules: A set of rules that define the designated fields to be masked and the masking function that is used. The designated fields can be defined using a database schema name, table name, and column name.
Masking functions: A set of methods that control the exposure of data for different scenarios.
Masking function
Masking logic
Default
Full masking according to the data types of the designated fields
* Use XXXX (or fewer) if the size of the field is fewer than 4 characters for string data types (nchar, ntext, nvarchar). * Use a zero value for numeric data types (bigint, bit, decimal, int, money, numeric, smallint, smallmoney, tinyint, float, real). * Use 1900-01-01 for date/time data types (date, datetime2, datetime, datetimeoffset, smalldatetime, time). * For sql_variant, the default value of the current type is used. * For XML, the document <masked /> is used. * Use an empty value for special data types (timestamp, table, HierarchyID, uniqueidentifier, binary, image, varbinary, and spatial types).
Credit card
Masking method, which exposes the last four digits of the designated fields and adds a constant string as a prefix in the form of a credit card.
XXXX-XXXX-XXXX-1234
Email
Masking method, which exposes the first letter and replaces the domain with XXX.com using a constant string prefix in the form of an email address.
aXX@XXXX.com
Random number
Masking method, which generates a random number according to the selected boundaries and actual data types. If the designated boundaries are equal, then the masking function is a constant number.
Custom text
Masking method, which exposes the first and last characters and adds a custom padding string in the middle. If the original string is shorter than the exposed prefix and suffix, only the padding string is used.
prefix[padding]suffix
Recommended fields to mask
The DDM recommendations engine flags certain fields from your database as potentially sensitive fields, which might be good candidates for masking. In the Dynamic Data Masking pane in the portal, you see the recommended columns for your database. Select Add Mask for one or more columns, then select the appropriate masking function and select Save, to apply mask for these fields.
To learn more about permissions when using dynamic data masking with T-SQL command, see Permissions.
Granular permission example
Prevent unauthorized access to sensitive data and gain control by masking it to an unauthorized user at different levels of the database. You can grant or revoke UNMASK permissions at the database-level, schema-level, table-level or at the column-level to any database user or role. Combined with Microsoft Entra authentication, UNMASK permissions can be managed for users, groups, and applications maintained within your Azure environment. The UNMASK permission provides a granular way to control and limit unauthorized access to data stored in the database and improve data security management.
CREATEUSER ServiceAttendant WITHOUT LOGIN;
GO
CREATEUSER ServiceLead WITHOUT LOGIN;
GO
CREATEUSER ServiceManager WITHOUT LOGIN;
GO
CREATEUSER ServiceHead WITHOUT LOGIN;
GO
Grant read permissions to the users in the database:
--Grant column level UNMASK permission to ServiceAttendantGRANT UNMASK ON Data.Membership(FirstName) TO ServiceAttendant;
-- Grant table level UNMASK permission to ServiceLeadGRANT UNMASK ON Data.Membership TO ServiceLead;
-- Grant schema level UNMASK permission to ServiceManagerGRANT UNMASK ONSCHEMA::DataTO ServiceManager;
GRANT UNMASK ONSCHEMA::Service TO ServiceManager;
--Grant database level UNMASK permission to ServiceHead;GRANT UNMASK TO ServiceHead;
Query the data under the context of user ServiceAttendant:
SQL
EXECUTEASUSER = 'ServiceAttendant';
SELECT MemberID, FirstName, LastName, Phone, Email, BirthDay
FROM Data.Membership;
SELECT MemberID, Feedback, Rating
FROM Service.Feedback;
REVERT;
Query the data under the context of user ServiceLead:
SQL
EXECUTEASUSER = 'ServiceLead';
SELECT MemberID, FirstName, LastName, Phone, Email, BirthDay
FROM Data.Membership;
SELECT MemberID, Feedback, Rating
FROM Service.Feedback;
REVERT;
Query the data under the context of user ServiceManager:
SQL
EXECUTEASUSER = 'ServiceManager';
SELECT MemberID, FirstName, LastName, Phone, Email, BirthDay
FROM Data.Membership;
SELECT MemberID, Feedback, Rating
FROM Service.Feedback;
REVERT;
Query the data under the context of user ServiceHead
SQL
EXECUTEASUSER = 'ServiceHead';
SELECT MemberID, FirstName, LastName, Phone, Email, BirthDay
FROM Data.Membership;
SELECT MemberID, Feedback, Rating
FROM Service.Feedback;
REVERT;
To revoke UNMASK permissions, use the following T-SQL statements:
SQL
REVOKE UNMASK ON Data.Membership(FirstName) FROM ServiceAttendant;
REVOKE UNMASK ON Data.Membership FROM ServiceLead;
REVOKE UNMASK ONSCHEMA::DataFROM ServiceManager;
REVOKE UNMASK ONSCHEMA::Service FROM ServiceManager;
REVOKE UNMASK FROM ServiceHead;
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.