There are cases where you might need to restore an entire SQL Server database (i.e. in the case of loss of data, etc.) on another SQL Server instance. A set of objects that are restored from the backup set and are included in the restored database are the database users. However, in such cases, the SQL Server logins are not restored, since they are server-level objects. This article explains how to create logins for orphaned database users in SQL Server.
In this case, you can use the following stored procedure for fixing such issues: sp_change_users_login
Syntax example for creating a login for an oprhaned database user in SQL Server
USE AdventureWorks
GO
EXEC sp_change_users_login 'Auto_Fix', 'UserName', NULL, 'Password';
GO
The above example will create a new SQL Server Login for the given user name and use as a password the given password string.
You can also assign existing logins to orphaned users, again by using the sp_change_users_login stored procedure.
Find and Handle Orphaned Database Users with DBA Security Advisor
DBA Security Advisor, is our SQL Server security tool, which can help you analyze your SQL Server Instances for security misconfigurations, and get useful recommendations.
The way it works, is that you select the security checks you want to perform, you then connect to one or more SQL Server instances, run the assessment, and you get a comprehensive report with recommendations.
One of the security checks, is checking for orphaned users.
Via the course, you will learn essential hands-on SQL Server Administration tips on SQL Server maintenance, security, performance, integration, error handling and more. Many live demonstrations and downloadable resources included!
(Lifetime Access/ Live Demos / Downloadable Resources and more!)
Artemakis Artemiou is a Senior SQL Server Architect, Author, a 9 Times Microsoft Data Platform MVP (2009-2018) and a Udemy Instructor. He has over 15 years of experience in the IT industry in various roles. Artemakis is the founder of SQLNetHub and TechHowTos.com. Artemakis is the creator of the well-known software tools Snippets Generator and DBA Security Advisor. Also, he is the author of many eBooks on SQL Server. Artemakis currently serves as the President of the Cyprus .NET User Group (CDNUG) and the International .NET Association Country Leader for Cyprus (INETA). Moreover, Artemakis teaches on Udemy, you can check his courses here.
This site uses cookies for personalized content and the best possible experience. By continuing to browse this site, you agree to this use. Find out more.