Technical Article

Orphan Users

,

The above script is used to fix orphan login and tested in SQL 2000 & SQL 2005.

USE [DBName]
GO


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

SELECT     @SQLString = @SQLString + 'EXEC [dbo].[sp_Change_Users_Login] ''Update_One'','''+[Name]+''','''+[Name]+''' '
FROM     [dbo].[SysUsers]
WHERE     [IsSqlUser] = 1 
AND     (SId IS NOT NULL AND SId <> 0x0) 
AND     SUSER_SNAME(SId) IS NULL

IF LEN(LTRIM(RTRIM(@SQLString)))<>0 
BEGIN
    PRINT(@SQLString)
    EXEC(@SQLString)    
END
GO

Rate

1.67 (3)

You rated this post out of 5. Change rating

Share

Share

Rate

1.67 (3)

You rated this post out of 5. Change rating