2009年11月9日 星期一

SQL Server 2000資料庫中的使用者帳號對應到登入帳號

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''
--select name from sysusers where altuid=0 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 ''Update_One'', @name , @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

沒有留言:

張貼留言