MSSQL 刪除數(shù)據(jù)庫里某個用戶所有表里的數(shù)據(jù)
更新時間:2009年09月21日 18:14:08 作者:
刪除數(shù)據(jù)庫里某個用戶所有表里的數(shù)據(jù)的實現(xiàn)語句。
-->Title:刪除數(shù)據(jù)庫里某個用戶所有表里的數(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'')'
-->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'')'
相關(guān)文章
淺談SQL Server中統(tǒng)計對于查詢的影響分析
SQL Server查詢分析器是基于開銷的。通常來講,查詢分析器會根據(jù)謂詞來確定該如何選擇高效的查詢路線,比如該選擇哪個索引2012-05-05SQL Server在AlwaysOn中使用內(nèi)存表的“踩坑”記錄
這篇文章主要給大家介紹了關(guān)于SQL Server在AlwaysOn中使用內(nèi)存表的一些"踩坑"記錄,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習下吧。2017-09-09用SQL語句實現(xiàn)隨機查詢數(shù)據(jù)并不顯示錯誤數(shù)據(jù)的方法
用SQL語句實現(xiàn)隨機查詢數(shù)據(jù)并不顯示錯誤數(shù)據(jù)的方法...2007-11-11SQLServer 使用ADSI執(zhí)行分布式查詢ActiveDorectory對象
SQLServer 通過使用 ADSI 執(zhí)行分布式查詢ActiveDorectory對象的實現(xiàn)方法。2010-05-05SQL Server存儲過程中使用表值作為輸入?yún)?shù)示例
這篇文章主要介紹了SQL Server存儲過程中使用表值作為輸入?yún)?shù)示例,使用表值參數(shù),可以不必創(chuàng)建臨時表或許多參數(shù),即可向 Transact-SQL 語句或例程(如存儲過程或函數(shù))發(fā)送多行數(shù)據(jù),這樣可以省去很多自定義的代碼,需要的朋友可以參考下2015-07-07數(shù)據(jù)庫中經(jīng)常用到的操作和管理數(shù)據(jù)庫的語句總結(jié)
數(shù)據(jù)庫中經(jīng)常用到的操作和管理數(shù)據(jù)庫的語句,感謝作者的辛勤勞動,很多。2010-06-06