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
復(fù)制代碼 代碼如下:
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
復(fù)制代碼 代碼如下:
exec sp_msforeachtable @command1="truncate table ? ;",@whereand='and schema_id = (select schema_id from sys.schemas where [name] =''Stone'')'
相關(guān)文章
SQL 復(fù)合查詢條件(AND,OR,NOT)對NULL值的處理方法
在SQL的3值邏輯下,一個查詢條件可以產(chǎn)生以下三種情況:TRUE,FALSE,NULL。只有那些滿足WHERE子句的值是TRUE的記錄才出現(xiàn)在結(jié)果表中。2011-04-04
Sql Server里刪除數(shù)據(jù)表中重復(fù)記錄的例子
這篇文章主要介紹了Sql Server里刪除數(shù)據(jù)表中重復(fù)記錄的例子,本文給出了3種操作方法,需要的朋友可以參考下2014-08-08
sqlserver substring函數(shù)使用方法小結(jié)
在操作sqlserver時候用到了substring函數(shù),特整理一些實例,需要的朋友可以參考下。2009-12-12
SQL Server數(shù)據(jù)庫自動備份的實現(xiàn)步驟
要編寫一個自動備份 SQL Server 數(shù)據(jù)庫的腳本,可以使用 SQL Server Management Studio (SSMS) 或者 Transact-SQL (T-SQL) 腳本,本文給大家介紹了一個一個簡單的 T-SQL 腳本示例,需要的朋友可以參考下2023-11-11
MSSQL MySQL 數(shù)據(jù)庫分頁(存儲過程)
有關(guān)分頁 SQL 的資料很多,有的使用存儲過程,有的使用游標。本人不喜歡使用游標,我覺得它耗資、效率低;使用存儲過程是個不錯的選擇,因為存儲過程是經(jīng)過預(yù)編譯的,執(zhí)行效率高,也更靈活2012-01-01

