First of all, as an admin of SQL Server, I'm trying to use standard database for masking column.
CREATE TABLE [Person].[MyEmailAddress]
(
[MyBusinessEntityID] [int] NOT NULL,
[MyEmailAddressID] [int] IDENTITY(1,1) NOT NULL,
[EmailAddress] [nvarchar](50) MASKED WITH (FUNCTION = 'email()') NULL, --<== masked
[rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL,
[ModifiedDate] [datetime] NOT NULL,
CONSTRAINT [PK_MyEmailAddress_BusinessEntityID_EmailAddressID] PRIMARY KEY CLUSTERED (
[MyBusinessEntityID] ASC,
[MyEmailAddressID] ASC
)
) ON [PRIMARY]
GO
Then, I created a new stored procedure
CREATE PROCEDURE [Person].[Email_Address]
AS
BEGIN
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT * from [Person].[EmailAddress]
END
GO
Then, I created a new login user
create login AdvUserTest004
with password = 'Test123'
create user User004
for login AdvUserTest004
-- add user to the database owner role
exec sp_addrolemember N'db_owner', N'User004'
Setting the user role by referring this link to db_datawriter
and db_datareader
. Without these two memberships, the tables didn't appear.
Then, I tried to login with 'AdvUserTest004' with SQL Server authentication mode. Tried to execute select statement
select * from [Person].[EmailAddress]
The output result looks good, masked.
But the stored procedure above didn't appear. So, by referring this document, giving permission to execute.
Now, stored procedure appear as usual. Then, execute the stored procedure
exec [Person].[Email_Address]
The result looks like this:
So the question is,
- Why is the email column unmasked when it executes in stored procedure but it is masked in select statement?
- How should the email column mask when it executes in stored procedure?