I have a SQL Server 2017 instance with 5 databases on it. A, B, C, D, E. Database A holds nothing but schemas and views. There is one schema for each of the subsequent databases on the instance (A, B, C, D, E) and each schema has 50 - 150 views it owns.
I need the ability to give user(s) select permissions to all the views in database A but deny select permissions to ALL of the tables directly.
The test conditions should look like this.
SELECT * FROM [B].dbo.[any_table] (DENIED)
SELECT * FROM [A].[B].some_view (WORKS)
Since schema A - E are all owned by dbo I assumed I could just do the following:
USE A
GO
CREATE ROLE db_viewreader
GO
GRANT SELECT ON SCHEMA::A TO db_viewreader (repeat for b, c, d, e)
GO
CREATE USER testuser WITHOUT LOGIN
GO
ALTER ROLE db_viewreader ADD MEMBER testuser
GO
EXECUTE AS USER = 'testuser'
SELECT *
FROM [A].[B].some_view
I cannot get results from the view or the table. I THINK I understand why I am not getting results querying the tables since the user I created does not exist in database B - E. Is that the same reason I cannot call a view that accesses data in those underlying tables? If so Is there any way I can create a user that can utilize the views but not the tables they sit on top of?