DECLARE @tab TABLE ( id int identity(1,1), uname sysname )
DECLARE @id int
, @uname sysname
, @sql nvarchar(4000)
INSERT INTO @tab ( uname )
SELECT name
FROM sysusers
WHERE issqluser = 1
AND hasdbaccess = 1
AND name != 'dbo'
SELECT @id = max(id) from @tab
WHILE @id > 0
BEGIN
SELECT @uname = uname
FROM @tab
WHERE id = @id
EXEC sp_change_users_login @action = 'Update_One', @UserNamePattern = @uname, @LoginName = @uname
SET @id = @id - 1
END
Used to use sp_change_users_login, but since that is now deprecated, it is recommended to use the following:
alter user [joeuser] with login = [joeuser]
No comments:
Post a Comment