EXECUTE master.sys.sp_MSforeachdb 'USE [?]; IF DB_Name() NOT IN (''Master'', ''Tempdb'', ''model'', ''msdb'' ,''distribution'')
BEGIN
begin try
create user masterReadOnlyUser for login masterReadOnlyUser
print ''Agrega el usuario masterReadOnlyUser a la base de datos ''+ DB_NAME()
end try
begin catch
print ''Error: ''+ERROR_MESSAGE ( )
end catch
begin try
exec sp_addrolemember ''db_datareader'',''masterReadOnlyUser''
print ''Agrega rol db_datareader al usuario masterReadOnlyUser en la base de datos ''+ DB_NAME()
end try
begin catch
print ''Error: ''+ERROR_MESSAGE ( )
end catch
END
'