2009年11月26日 星期四

MSSQL 權限設定回復方法

declare @dbname nvarchar(200), @cmd2 nvarchar(2000)
declare c_db cursor for
select name from sysdatabases where dbid > 4
open c_db fetch next from c_db into @dbname
while @@fetch_status=0
begin
print @dbname
set @cmd2='use '+@dbname + ' ' +
'
declare @name nvarchar(200), @cmd nvarchar(200)
declare c_user cursor for
select name from sysusers where altuid is null and createdate > ''2001/1/1''


open c_user
fetch next from c_user into @name
while @@fetch_status=0
begin
print @name
exec sp_change_users_login ''Auto_Fix'', @name
fetch next from c_user into @name
end
close c_user
deallocate c_user
'
exec (@cmd2)
--print (@cmd2)
fetch next from c_db into @dbname
end
close c_db
deallocate c_db

--altuid is null (SQL Server 2008) §令 altuid = 0 (SQL Server 2000)
-- exec sp_change_users_login ''Update_One'',@name,@name (SQL Server 2008)
-- ''Auto_Fix'', @name (SQL Server 2000)

沒有留言:

張貼留言