Technical Article

Synchronize SID with Login SID - No CURSOR

,

USE [DBName]
GO

DECLARE @SQLString VARCHAR(7500)
SELECT@SQLString = ''

SELECT@SQLString = @SQLString + 'EXEC sp_Change_Users_Login ''UPDATE_ONE'','+QUOTENAME([Name],'''')+','+QUOTENAME([Name],'''')+'; '
FROMSysUsers
WHEREIsSQLUser = 1
AND(SId IS NOT NULL AND SId <> 0x0)
ANDSUSER_SNAME(SId) IS NULL
ORDER BY [Name]

PRINT @SQLString
EXEC(@SQLString)

By
Ram Ramamoorthy

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating