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