Database Security Question

  • Hi All,

    we have a sql server instance which consists of 200 databases. A user called Jack has DB_reader permission on all the databases and i want to change jack's permission from DB_reader to DB_writer.

    How can i do this in a single shot using T-SQL/Mgmt Studio ?

  • Look into sp_MSForEachDB (hidden MS procedure)

    sp_MSforeachdb 'if ''?'' NOT IN (''tempdb'',''master'',''model'',''msdb'') use ? EXEC sp_droprolemember N'db_datareader', N'Jack'

    sp_MSforeachdb 'if ''?'' NOT IN (''tempdb'',''master'',''model'',''msdb'') use ? EXEC sp_addrolemember N'db_datawriter', N'Jack'

    Otherwise you can always look through a cursor of all User Databases

    SQLServerNewbieMCITP: Database Administrator SQL Server 2005

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply