發表于:2009-12-21 00:00:00來(lái)源:易陽網絡人(rén)氣:3860
以下是引用片段: sql server 批量修改表和存儲過程的所有者 --執行這個語句,可(kě)以把當前庫的所有表的所有者改爲 dbo exec sp_msforeachtable 'sp_changeobjectowner ''?'', ''dbo''' --如(rú)果是要用戶表/存儲過程/視圖/觸發器/自(zì)定義函數一齊改,則用遊标(不要理(lǐ)會錯誤提示) 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 |