MSSQL 刪除數(shù)據(jù)庫(kù)里某個(gè)用戶所有表里的數(shù)據(jù)
更新時(shí)間:2009年09月21日 18:14:08 作者:
刪除數(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'')'
-->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)對(duì)NULL值的處理方法
在SQL的3值邏輯下,一個(gè)查詢條件可以產(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時(shí)候用到了substring函數(shù),特整理一些實(shí)例,需要的朋友可以參考下。2009-12-12
SQL?Server中實(shí)現(xiàn)錯(cuò)誤處理
這篇文章介紹了SQL?Server中實(shí)現(xiàn)錯(cuò)誤處理的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05
SQLServer數(shù)據(jù)庫(kù)如何還原重命名
這篇文章主要介紹了SQLServer數(shù)據(jù)庫(kù)如何還原重命名問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06
SQL Server數(shù)據(jù)庫(kù)自動(dòng)備份的實(shí)現(xiàn)步驟
要編寫一個(gè)自動(dòng)備份 SQL Server 數(shù)據(jù)庫(kù)的腳本,可以使用 SQL Server Management Studio (SSMS) 或者 Transact-SQL (T-SQL) 腳本,本文給大家介紹了一個(gè)一個(gè)簡(jiǎn)單的 T-SQL 腳本示例,需要的朋友可以參考下2023-11-11
MSSQL MySQL 數(shù)據(jù)庫(kù)分頁(yè)(存儲(chǔ)過(guò)程)
有關(guān)分頁(yè) SQL 的資料很多,有的使用存儲(chǔ)過(guò)程,有的使用游標(biāo)。本人不喜歡使用游標(biāo),我覺(jué)得它耗資、效率低;使用存儲(chǔ)過(guò)程是個(gè)不錯(cuò)的選擇,因?yàn)榇鎯?chǔ)過(guò)程是經(jīng)過(guò)預(yù)編譯的,執(zhí)行效率高,也更靈活2012-01-01

