Grant SELECT permission on a view, but not on underlying objects

前端 未结 3 1479
名媛妹妹
名媛妹妹 2020-12-03 10:12

I often read that one purpose of a VIEW is security: to allow some users access to the underlying table, and other users to a derived view only. With that in mind I designed

3条回答
  •  甜味超标
    2020-12-03 10:44

    You might find the information in this forum helpful.

    The last post has the details of what was run to grant permissions to a view but not the underlying tables:

    CREATE USER [Reports] FOR LOGIN [Reports] WITH DEFAULT_SCHEMA = Reports
    CREATE SCHEMA Reports AUTHORIZATION Reports --Auth as Reports was the key piece of information that I had missed.
    GO
    CREATE ROLE Reporting AUTHORIZATION db_securityadmin
    GO
    exec sp_addrolemember @rolename = 'Reporting', @membername = 'Reports'
    GO
    GRANT CREATE VIEW TO Reporting
    GRANT CREATE TABLE TO Reporting
    
    GRANT SELECT, VIEW DEFINITION ON [dbo].[zName] TO Reporting;
    

    FYI - For stored procedures, you should be granting EXEC to the procedure.

提交回复
热议问题