Is it possible to grant a user access to a view but restrict the user from accessing the table the view selects from?
CREATE TABLE [dbo].[tUsers](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Username] [nvarchar](50) NULL,
[Password] [nvarchar](50) NULL,
[TenantID] int
) ON [PRIMARY]
CREATE VIEW [scmTenant1].[vUsers]
AS
SELECT ID, Username, Password
FROM dbo.tUsers
WHERE TenantID = 1
The SQL Server user account (usrTenant1
) has access to schema scmTenant1
but does not have access to the dbo
schema. I log into SQL Server Management Studio as usrTenant1
and try executing this query:
SELECT * FROM scmTenant1.vUsers
Gives me error:
The SELECT permission was denied on the object 'tUsers', database 'Sandbox', schema 'dbo'.
If I grant this account access to the dbo
schema the query executes fine.
I think what I would really like to grant the view permission to the table. But my question is can you grant a user access to a view and restrict that user from accessing the underlying table the view selects from?