刪除庫中所有表中的資料

2022-03-08 21:38:03 字數 828 閱讀 5699

declare

@tablename

nvarchar(250)--

宣告讀取資料庫所有資料表名稱游標mycursor1

declare mycursor1 cursor

forselect name from dbo.sysobjects where

objectproperty(id, '

isusertable

') =

1open

mycursor1

--從游標裡取出資料賦值到我們剛才宣告的資料表名變數中

fetch

next

from mycursor1 into

@tablename

--如果游標執行成功

while (@@fetch_status=0

)begin

--執行刪除

--exec('truncate table ['+@tablename+']')

exec('

delete from ['+

@tablename+'

]')

--用游標去取下一條記錄

fetch

next

from mycursor1 into

@tablename

end--

關閉游標

close

mycursor1

print

'游標1關閉'--

撤銷游標

deallocate

mycursor1

print

'撤銷遊1

'

sql server 刪除資料庫中所有表資料

1.清空所有資料表中的記錄 exec sp msforeachtable command1 truncate table 2.刪除所有資料表 exec sp msforeachtable delete n 如果出現 資料表中有各種約束,就不能使用上面的方法來刪除資料了,只能使用以下方式 建立自定義儲...

mysql刪除表中所有資料

delete from表名 truncate table表名 不帶where 引數的delete 語句可以刪除 mysql 表中所有內容,使用 truncate table 也可以清空 mysql 表中所有內容。效率上truncate 比delete 快,但truncate 刪除後不記錄 mysql...

mysql清空庫中所有表的資料

清除表資料 select concat truncate table table name,from information schema.tables where table schema db1 執行後生成的是清除語句,複製之後貼上再次執行。修改表備註 select concat alter t...