程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> 其他數據庫知識 >> 更多數據庫知識 >> 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'')'

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved