0

I'm new to the role of being a SQL Server DBA for SQL Server 2008 R2.

I need help on how to find out orphaned users in SQL Server and how to delete/remove the orphaned users and their corresponding schema from the database.

Please provide a step by step solution.

John K. N.
  • 18,854
  • 14
  • 56
  • 117

1 Answers1

0
  1. To find out the orphan users of a database say "ABC", you need to query below on that database:i.e

    USE ABC
    
    sp_change_users_login @Action='Report'
    
  2. This will list out all the orphan database users for that database. In order to resolve the orphan users, use sp_change_users_login, with query below

    USE ABC
    
    sp_change_users_login
        @Action='update_one',   
        @UserNamePattern='database_user_name_comes_here', 
        @LoginName='login_name_comes_here'
    

Also, suggested reads: How To Avoid Orphaned Database Users with SQL Server Authentication and Fixing Orphan users

Paul White
  • 94,921
  • 30
  • 437
  • 687
KASQLDBA
  • 7,203
  • 6
  • 30
  • 53