The tough part was to get the DB name in the result set. Then, it hit me... do this:
$0$0
$0
$0
$0CREATE TABLE #temporphans(UserName Varchar(100), UserSID Varchar(100), dbName varchar(100) null)$0
$0GO$0
$0$0
$0
$0EXEC sp_MSforeachdb @command1 ='$0
$0USE [?]$0
$0INSERT INTO #temporphans (UserName, UserSID)$0
$0$0
$0
$0EXEC [sp_change_users_login] @Action=''Report'';$0
$0$0
$0
$0UPDATE #temporphans SET dbName = ''?'' WHERE dbName IS NULL;$0
$0'$0
$0$0
$0
$0SELECT dbName,UserN
↧