Solved

List Orphan User & role  and delete Orphan User who Don't Have sysadmin Role

Posted on 2009-04-10
2
864 Views
Last Modified: 2012-05-06
I am looking for a script that will list orphan user & roles and a script that will delete all orphan users who do not have sysadmin role. This needs to work with SQL Server 2000 & 2005.
0
Comment
Question by:Omega002
  • 2
2 Comments
 
LVL 17

Accepted Solution

by:
k_murli_krishna earned 500 total points
ID: 24117418
All of these instructions should be done as a database admin, with the restored database selected.
This will lists the orphaned users:
EXEC sp_change_users_login 'Report'
If you already have a login id and password for this user, fix it by doing:
EXEC sp_change_users_login 'Auto_Fix', 'user'
If you want to create a new login id and password for this user, fix it by doing:
EXEC sp_change_users_login 'Auto_Fix', 'user', 'login', 'password'

Also, refer:
http://www.mssqltips.com/tip.asp?tip=1590
For orphaned role, refer:
http://www.eggheadcafe.com/forumarchives/SQLServerserver/Jun2005/post23408248.asp
 
0
 
LVL 17

Assisted Solution

by:k_murli_krishna
k_murli_krishna earned 500 total points
ID: 24117472
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question