To auto fix orphaned users safely is a surprisingly complex task. But, as demonstrated in this article, it is possible if you follow a handful of rules.
Scripting all logins on a SQL Server instance can be helpful e.g. when setting up a test or development environment. Read on to see an example query for just this purpose.
To re-create a login on a different SQL Server instance while preserving the password you can use the CREATE LOGIN statement with the hashed password. Read on for a detailed explanation.
To access a database in SQL Server, a login needs to have an associated user in that database. Read on to see how that association is implemented and what you need to do to repair it if it breaks.
LOGINPROPERTY is a SQL Server catalog function that can be used to query a total of twelve properties for SQL Logins not even revealed by the sys.sql_logins catalog view. Read on to find out how to use LOGINPROPERTY and which properties it can return.