有时我们需要将一个Sql Server实例的Login信息(Security->Logins)批量导出到另一个实例,这时如果手工建立会比较费时费力,我们可以用Sql语句来快速完成,具体语句可以参考下面:
Quick Import Sql Server Logins
select 'exec master.dbo.sp_addsrvrolemember @loginame=''' + member.name + ''', @rolename=''' + roles.name + ''''
from sys.server_role_members
join sys.server_principals roles on role_principal_id = roles.principal_id
join sys.server_principals member on member_principal_id = member.principal_id