When I restore SQL Server backup I need to clean orphaned users (SQL authentication) in other words I lose mapping between database user and SQL Server login which is outside of any specific databases.
To fix it I use sp_change_users_login stored procedure:
To find orphaned users I open new query window select database I want to check for orphans (or type USE database) and run the following line:
exec sp_change_users_login 'report'
This shows me a list of orphaned users in this particular database to fix I use the same stored procedure however the first argument is auto fix and second argument is username name which I want to fix.
exec sp_change_users_login 'auto_fix', 'username'
This gives me the following result
The row for user 'username' will be fixed by updating its login link to a login already in existence.
The number of orphaned users fixed by updating users was 1.
The number of orphaned users fixed by adding new logins and then updating users was 0.
So that is how I clean orphaned users in SQL Server. Microsoft sp_change_users_login says this featuer will be removed and you should use alter user but for now that works for me. When I find time I will try to find alter user script and update this post.