Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Script to Add User to all Databases Expand / Collapse
Author
Message
Posted Wednesday, January 19, 2011 11:29 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 9:21 AM
Points: 977, Visits: 3,358
Hello Everyone
I have lost my script that I use to add a user to all databases.

Does anyone have one handy that you could share with me?

Thanks
Andrew SQLDBA
Post #1050257
Posted Thursday, January 20, 2011 5:19 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:17 AM
Points: 13,238, Visits: 11,011
Is this what you're looking for?

http://sqlserverplanet.com/security/add-users-to-database-script/

(don't know if it works properly, I just did a quick google search)




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1050650
Posted Monday, April 11, 2011 2:25 PM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, April 8, 2014 10:49 PM
Points: 73, Visits: 320
This script will add the user to each DB, but you must have the Login created first.
It will add the user as a db_datareader role.
sp_msforeachdb 'use [?]; CREATE USER [MyDBUser] FOR LOGIN [MyDBLogin];EXEC sp_addrolemember ''db_datareader'', ''MyDBUser'''

Enjoy


QUIGROUP- Need a Certified experienced DBA for a project or troubleshooting? Need help with programming, database recovery, performance tuning, ETL, SSRS or developing new databases? Contact us.. 1-786-273-9809
Post #1091747
Posted Thursday, February 21, 2013 9:42 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, February 22, 2013 1:58 PM
Points: 1, Visits: 11
That script doesn't actually work. But here is one that will:

exec sp_msforeachdb 'use [?]; CREATE USER [UserName] FOR LOGIN [UserName];EXEC sp_addrolemember db_datareader, [UserName]'
Post #1422675
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse