Is there a way to change permissions for all the tables in SQL-server database at once?
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.
精彩评论