开发者

Is there a way to change permissions for all the tables in SQL-server database at once?

开发者 https://www.devze.com 2022-12-15 12:01 出处:网络
I want to change the permissions for all the tables in a SQL-Server database at once. Is there a way to do t开发者_StackOverflow中文版his?Run the results of this script (change to suit your requiremen

I want to change the permissions for all the tables in a SQL-Server database at once. Is there a way to do t开发者_StackOverflow中文版his?


Run the results of this script (change to suit your requirements):

SELECT
    'GRANT SELECT ON ' + OBJECT_NAME(o.object_id) + ' TO myRole'
FROM
    sys.objects o
WHERE
    OBJECTPROPERTY(o.object_id, 'IsMSSHipped') = 0
    AND
    OBJECTPROPERTY(o.object_id, 'IsTable') = 1
ORDER BY
    OBJECT_NAME(o.object_id)


Provided all of your tables belong to the same schema, you could modify permissions at the Schema level.

See Grant Schema Permissions


You can write a script that retrieves the set of tables and then grants/denies permissions through dynamic SQL.

However, I think a better approach would be to create a role, grant rights to that role, and then add/remove individuals from that role as needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号