Wednesday, March 28, 2012

Script to Set User Permissions to Insert and Update Only

Is there a script built into SQL Server that given a specific user and
database will change the user's permission to only insert and update
tables? (I'd like to avoid the task to manually having to do this using
the GUI.)
Alternatively, the user is part of the "Public" role. Is there a script
to change the Public role such that the condition above is true?
Thanks
O.B. wrote:
> Is there a script built into SQL Server that given a specific user and
> database will change the user's permission to only insert and update
> tables? (I'd like to avoid the task to manually having to do this
> using the GUI.)
> Alternatively, the user is part of the "Public" role. Is there a
> script to change the Public role such that the condition above is
> true?
> Thanks
If the group already has rights then revoke them:
Revoke Delete, Select on <table_name> From Public
If the group does not yet have rights, then grant them:
grant insert, update on whatever to public
However, to run some Update queries, you may need to grant Select
rights. For example:
Update dbo.MyTable Set Col1 = 10 -- works without SELECT grant
Update dbo.MyTable Set Col1 = 10 Where Col2 = 5 -- does not work withotu
SELECT grant
David Gugick
Quest Software
www.imceda.com
www.quest.com

No comments:

Post a Comment