How to Grant Select rights on all views including future views in SQL Server

Hazir 11 Reputation points
2021-06-10T04:01:55.45+00:00

I have multiple views and want to create more views in SQL Server. I want to grant select rights automatically to some users as I create view. Kindly mention code.

Developer technologies | Transact-SQL
SQL Server | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Cris Zhan-MSFT 6,661 Reputation points
    2021-06-10T07:05:56.883+00:00

    Hi,

    If these users currently do not have permission to access the view object.

    For the existing view, you can go to the Properties of the view in SSMS, add users in the Permissions, and then grant select permission in the permissions list. Or use the following statement to grant user permissions:

    use YourDB
    GRANT SELECT ON OBJECT::[schema].[yourview] TO User1,User2
    

    For views to be created in the future, you cannot grant user any permission while creating them. You can choose to grant permissions after creating views.

    Or create a new schema for these views, and grant these users the right to select objects in this schema .It is necessary to ensure that the owner of the schema of the original tables and the schema where the view is located are the same.

    use YourDB
    GRANT select ON Schema :: [DBO] TO User1
    

    Note that you can GRANT SELECT permissions on a Schema, but you are unable to limit the SELECT privileges to views only.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.