MSSQL 刪除數據庫裡某個用戶一切內外的數據。本站提示廣大學習愛好者:(MSSQL 刪除數據庫裡某個用戶一切內外的數據)文章只能為提供參考,不一定能成為您想要的結果。以下是MSSQL 刪除數據庫裡某個用戶一切內外的數據正文
-->Title:刪除數據庫裡某個用戶一切內外的數據
-->Author:wufeng4552
-->Date :2009-09-21 15:08:41
--辦法1
declare @uname varchar(20)
declare cuser cursor for
select so.name
from sysobjects so,sysusers su where so.uid=su.uid and su.name='Stone'
and so.xtype='U'
open cuser
fetch next from cuser into @uname
while(@@fetch_status=0)
begin
exec('truncate table [Stone].['+@uname+']')
fetch next from cuser
end
close cuser
deallocate cuser
--辦法2
exec sp_msforeachtable @command1="truncate table ? ;",@whereand='and schema_id = (select schema_id from sys.schemas where [name] =''Stone'')'