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],'''')+'; '
FROM	SysUsers
WHERE	IsSQLUser = 1
AND	(SId IS NOT NULL AND SId <> 0x0)
AND	SUSER_SNAME(SId) IS NULL
ORDER BY [Name]

PRINT 	@SQLString
EXEC	(@SQLString)

By
Ram Ramamoorthy

Rate

Share

Share

Rate