An orphaned account is a database in which the account has only a user name and no login, so that the user exists in the sysusers system table in the user library and there is no corresponding record in the syslogins of the master database.
Orphaned accounts are typically produced in two ways:
1. Restore the backed-up database to another machine;
2. After reloading the system or SQL Server, only the user library is restored
The workaround is to use sp_change_users_login to fix it.
There are three ways to use sp_change_users_login
Usage 1:
EXEC sp_change_users_login ' report '
List orphaned users of the current database
Usage 2:
exec sp_change_users_login ' auto_fix ', ' User name '
You can automatically add a login with the same name that corresponds to the user name to syslogins
Usage 3:
exec sp_change_users_login ' update_one ', ' User name ', ' Login name '
Maps the user name to the specified login name.
SQL Server Orphaned users resolved