The logic is really simple: read the values from sysxlogins on the source server and generate a script that should be run on the destination server.
PRINT 'exec master..sp_configure ''allow updates'',1'
print 'go'
PRINT 'reconfigure with override'
print 'go'
set nocount on
SELECT 'INSERT INTO sysxlogins( sid, xstatus, xdate1, xdate2, name, password, dbid, language) VALUES' + char(13) + char(10)
+ '(',sid,','
+ convert(varchar(20),xstatus) + ',''' + convert(varchar(25),xdate1) + ''',''' + convert (varchar(25),xdate2)
+ ''',''' + rtrim(name) + ''',',password,',5,''us_english'')'
from master..sysxlogins
where name not in (
'sa','distributor_admin','distributor_admin')
and name not like '%\%'
and name is not null
print 'GO'
PRINT 'exec master..sp_configure ''allow updates'',0'
print 'go'
PRINT 'reconfigure with override'
print 'go'
1 commenti:
After publishing this post, I found sp_help_revlogin, a Microsoft provided utility that generates a TSQL script to migrate logins from one server to another. This SP will not only copy the existing logins, but it will also copy the passwords and Security Identification Numbers (SID) associated with SQL Server Authenticated users.
Source: http://www.databasejournal.com/features/mssql/article.php/2228611
Post a Comment