SQL Server Migration – Migrate Database with Instance Level Logins

migrationsql server

Is there a way to migrate database along with all users and logins at the instance and database levels?

I am aware of contained databases and orphan users and solution for that.

I am using SQL Server 2012, 2014, and 2016. I came across another blog that Import Export functionality can be used, but yet have to try it.

Best Answer

Check out this:

sp_help_revlogin

This stored procedure, provided by Microsoft in the link below, will generate a T-SQL script that will copy the logins, their passwords and their corresponding SIDs (or security identification number, which is usually the culprit here). This is also a great utility when the database has numerous users with various security levels and passwords.

https://support.microsoft.com/en-us/kb/918992

This scripts out all Instance level logins. You can use this scripts and re create logins and map them to database in destination server.

Hope this helps.