Created
May 14, 2025 21:22
-
-
Save JerryNixon/a21b866f64f1d249f1c96ad7d1bc85f0 to your computer and use it in GitHub Desktop.
Use data masking in SQL Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP USER IF EXISTS PeopleReader; | |
DROP TABLE IF EXISTS People; | |
CREATE TABLE People | |
( | |
Id INT PRIMARY KEY, | |
Name VARCHAR(100), | |
SSN VARCHAR(11) MASKED WITH | |
(FUNCTION = 'partial(0,"XXX-XX-",4)') | |
); | |
CREATE USER PeopleReader WITHOUT LOGIN; | |
GRANT SELECT ON People TO PeopleReader; | |
INSERT INTO People (Id, Name, SSN) | |
VALUES | |
(1, 'John Doe', '123-45-6789'), | |
(2, 'Jane Smith', '987-65-4321'), | |
(3, 'Alice Johnson', '555-55-5555'), | |
(4, 'Bob Brown', '111-22-3333'), | |
(5, 'Charlie Black', '444-44-4444'); | |
EXECUTE AS USER = 'PeopleReader'; | |
SELECT * FROM People; | |
REVERT; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment