runal_jagtap (11/27/2012)
Hi Friends,i have asked to perfrom a task to create a New login & then provide the access rights to a particular DB..
I did it with no time 🙂
After this i am asked to create 50 New Login's & give them DB access privilages to each of them..
The total Databses are 150 :w00t::w00t::w00t::w00t::w00t:
Please help me with a query where in i can perform this activity easily 🙁
Well, in general, you create multiple roles, each containing the permissions you want to give, and then you create users, to match the logins, in each database, and assign them to the appropriate roles.
In your case, you didn't give any information about the details, so we cannot help much with that.
are the permissions going to be exactly the same for all 150 databases? does every login have access to all 150 databases?
when you define that, we could offer scripts that use things like sys.databases to generate a script for each database;
something like this:
EXEC sp_MSforeachdb
'SELECT
''USE [?]
GO
CREATE ROLE [AlmostOwners]
EXEC sp_addrolemember N''''db_ddladmin'''', N''''AlmostOwners''''
EXEC sp_addrolemember N''''db_datareader'''', N''''AlmostOwners''''
EXEC sp_addrolemember N''''db_datawriter'''', N''''AlmostOwners''''
--can the users EXECUTE procedures? comment out if false
GRANT EXECUTE TO [AlmostOwners]
--allow the users to see view proc and function definitions
Grant View Definition ON SCHEMA::[dbo] To [AlmostOwners]
GO
'''
Lowell