how to give Log in permissions on more then 60 Database

  • Hi Experts,

    I have a more then 60 database in one of the server and want to give Single User and AD account "Read only" permission on all 60 database. I have added the User and AD account into SQL Security but don't want to click 60 times to give permission. Is there any script which I can use and it will apply permissions to all 60 database? or any other way which you Experts can tell me I will really appreciate your help.

    Thanks

  • In SSMS set results to text and run (replace DOMAIN\login_name with appropriate values):

    select 'USE ' + name + '

    GO

    CREATE USER [DOMAIN\login_name] FOR LOGIN [DOMAIN\login_name]

    GO

    EXEC sp_addrolemember N''db_datareader'', N''DOMAIN\login_name''

    GO

    '

    from master.sys.databases

    where database_id > 4

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

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