HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

Create database role to allow read access to all tables; write access to some

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
tablescreatereadallwritedatabaseallowrolesomeaccess

Problem

We have a database with over 1000 tables. I need to create a role that allows read only on all tables, as well as write access to two specific tables.

I was messing around with database roles, but whenever I went to add the tables, I had to hand select all 1000... is there a better way to do this?

Solution

Granting permissions on the schema (e.g. dbo) will cascade to all the objects in that schema. For individual exceptions you can just list those explicitly:

GRANT SELECT ON SCHEMA::dbo TO [role];
GO

GRANT INSERT, UPDATE --, DELETE
  ON dbo.table_they_can_write_to TO [role];

DENY SELECT ON dbo.table_they_cannot_read TO [role];

Code Snippets

GRANT SELECT ON SCHEMA::dbo TO [role];
GO

GRANT INSERT, UPDATE --, DELETE
  ON dbo.table_they_can_write_to TO [role];

DENY SELECT ON dbo.table_they_cannot_read TO [role];

Context

StackExchange Database Administrators Q#43704, answer score: 9

Revisions (0)

No revisions yet.