HiveBrain v1.2.0
Get Started
← Back to all entries
patternModerate

Is there a shorthand way to 'Auto_Fix' all Orphaned Users in an SQL Server 2008 R2 database?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
auto_fixorphaned2008allsqluserswayshorthanddatabaseserver

Problem

It's fairly straight forward to fix up a single orphaned SQL user to a login using:


EXEC sp_change_users_login 'Auto_Fix', 'user'

I could script this, but is there an existing stored procedure which automatically tries to fix up every orphaned user in a given database?

Solution

Ted Krueger (@onpnt on twitter) wrote a great script that does this. It adds logins for any user without a login and runs the auto_fix. He even wrote one that includes fixing Windows logins:

http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/fixing-orphaned-database-users

Of course if you want to test it first (or merely perform an audit) you can comment out the action lines (EXEC) and just print out the results.

Context

StackExchange Database Administrators Q#12817, answer score: 16

Revisions (0)

No revisions yet.