執行數據庫恢復後,我想運行一個動態腳本來修復ophaned用戶。下面的腳本循環執行sp_change_users_login'report'後顯示的所有用戶,並使用login = [username]語句應用「alter user [username]」來修復SID衝突。我發現了一個「上線15不正確的語法錯誤」,不能弄清楚爲什麼...幫助..腳本動態修復數據庫恢復後的ophaned用戶
DECLARE @Username varchar(100), @cmd varchar(100)
DECLARE userLogin_cursor CURSOR FAST_FORWARD
FOR
SELECT UserName = name FROM sysusers
WHERE issqluser = 1 and (sid IS NOT NULL AND sid <> 0×0)
AND suser_sname(sid) IS NULL
ORDER BY name
FOR READ ONLY
OPEN userLogin_cursor
FETCH NEXT FROM userLogin_cursor INTO @Username
WHILE @@fetch_status = 0
BEGIN
SET @cmd = ‘ALTER USER ‘[email protected]+‘ WITH LOGIN ‘[email protected]
EXECUTE(@cmd)
FETCH NEXT FROM userLogin_cursor INTO @Username
END
CLOSE userLogin_cursor
DEALLOCATE userLogin_cursor
我總是忘了括號[]。謝謝! – gates 2010-05-20 15:13:56
您是否驗證過用戶確實存在? – Kenneth 2010-05-20 17:48:28