Case Scenario
We are in the process of hardware movement form a lower configuration to a higher end box. Being the DBA, I am responsible to migrate the SQL Server along with all the databases, logins and related permissions. I planned the migration as – Install SQL Server on the new server followed by all the databases migration one by one. I am going to note down the step by step procedure for this. You can also use these steps while overwriting a database on the same server or refreshing a test or development database from the production database copy.
Resolution
Follow the following steps:
10. Save the script file.
11. Next, script out all the logins. Windows Login IDs are very easy to script, simple right click and Choose script but for SQL Login IDs, you would need to script out along with their passwords as well. The following script will help you to script out all SQL Logins with their passwords, which will be encrypted.
SET NOCOUNT ON
SELECT 'EXEC sp_addlogin @loginame = ''' + loginname + ''''
,', @defdb = ''' + dbname + ''''
,', @deflanguage = ''' + language + ''''
,', @encryptopt = ''skip_encryption'''
,', @passwd ='
, cast(password AS varbinary(256))
,', @sid ='
, sid
FROM syslogins
WHERE name NOT IN ('sa')
AND isntname = 0
12. Take the User roles mapping by following script, per database.
set nocount on
select 'USE ' + db_name() + ' GO '
UNION
select 'exec sp_addrolemember N''' + rtrim(g.name) + ''',N''' + u.name + ''''
from sysusers u, sysusers g, sysmembers m,master..syslogins l
wHERE l.SID = u.sid
and g.uid = m.groupuid
and u.uid = m.memberuid
and u.name<>'dbo'
Remarks:
Once all the scripts are ready, apply them on the newly restored database on the new server.
Don't wait until you have got problems. Get the expert's advice, optimize your SQL Server and relax.
Contact for a SQL Sever Health Checkup Guidance today!
Always reachable through: