批量更改mssql表用户为系统默认用户

--还原sql数据库以后,不管怎么样也无法登陆论坛,仔细检查才发现,sql server表还是以前建立的用户,而又无法删除,解决方法:
declare tb cursor local for
select 'sp_changeobjectowner ''['+replace(user_name(uid),']',']]')+'].['
+replace(name,']',']]')+']'',''dbo'''
from sysobjects
where xtype in('U','V','P','TR','FN','IF','TF') and status>=0
open tb
declare @s nvarchar(4000)
fetch tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch tb into @s
end
close tb
deallocate tb
go

 

复制以上代码在查询分析器里运行即可。

你可能感兴趣的:(MSSQL)