MSSQL 刪除數(shù)據(jù)庫(kù)里某個(gè)用戶所有表里的數(shù)據(jù)

刪除數(shù)據(jù)庫(kù)里某個(gè)用戶所有表里的數(shù)據(jù)的實(shí)現(xiàn)語(yǔ)句。

–>Title:刪除數(shù)據(jù)庫(kù)里某個(gè)用戶所有表里的數(shù)據(jù)
–>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”)’

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊7 分享
站長(zhǎng)的頭像-小浪學(xué)習(xí)網(wǎng)月度會(huì)員