Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favourite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved in your SSC briefcase from the favorites tab.
Download now (direct download link)

Fix users for SQL 7 thru 2008

By Mike Tutor,

Usage:

EXEC sp_fix_user_logins @DBName = <DataBase>, @Action = <ActionOption>, @User = <User Specification>

sp_fix_user_logins:
- Will work on SQL 7 thru SQL 2008 versions of SQL Server.
- Either reports or fixes lost and or orphaned users in the current database.
- Can report/fix users on one or all databases.
- Will NOT fix READ ONLY and Offline databases, and it will NOT remove Orphans that own oblects.
- Can automatically change object ownership if @ForceFix is set to 'FixLogin'
- Will change object ownership to dbo if FixLogin is indicated and no @Owner is provided

Orphan user: A user in the current database that has no corresponding login in master.
Lost user: A user in the current database that has a login in master but the sid is out of sync.

<DataBase> = The name of any valid user defined database, or '*' for all'

<ActionOption> =
Report or ReportAll: Displays a list of all lost or orphaned users
ReportLost: Displays a list of all lost users
ReportOrphans: Displays a list of all orphaned users
Fix or FixAll: Repairs all lost users (changes the sid) and removes all orphaned users that do not own objects.
FixLost: Repairs all lost users (changes the sid).
FixOrphans: Removes all orphaned users that do not own objects.

<User Specification> =
NULL or '*': All users
Anyhting else: A specific user only or you may use LIKE operators

<ForceFix> =
NULL
: Do Not change object ownership for orphaned users
FixLogin : If an orphaned user is to be removed and owns objects, then change ownership of objects owned

<Owner> =
NULL
: Change object ownership to dbo
<username> : If the orphaned user owns objects then change ownership of objects owned to this user

Total article views: 2066 | Views in the last 30 days: 12
 
Related Articles
ARTICLE

Understanding Object Ownership

In SQL Server 2005, object ownership will have a different meaning, but since most of us work with S...

FORUM

SQL Server 2005 Best Practices - How Best To Change The Ownership Of Many Objects

What is the Best Practices approach within SQL 2005 to changing the ownership of multiple objects of...

FORUM

How to change ownership of table

How to change ownership of table in sql 2000

FORUM

CHANGING DB-OWNERSHIP TO SA ACCOUNT

CHANGING DB-OWNERSHIP TO SA ACCOUNT

FORUM

How to change Filegroup's ownership (URGENT)

How to change Filegroup's ownership (URGENT)

Tags
database restore    
logins    
users    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones