清空資料庫資料保留表結構

2021-09-10 02:32:14 字數 525 閱讀 9589

方法1:重建庫和表

用mysqldump --no-data把建表sql匯出來,然後drop database再create database,執行一下匯出的sql檔案;

方法2:生成清空所有表的sql

select concat(『truncate table 『,table_name,』;』) from information_schema.tables where table_schema = 『db1』

匯出到檔案

select concat(『truncate table 『,table_name,』;』) into outfile 『/website/truncatetable.sql』 from information_schema.tables where table_schema = 『db1』

查詢資料庫中有多少表

select count(*) tables, table_schema from information_schema.tables where table_schema = 『k3_ba』

資料庫清空表

常用的清空資料表的sql語句有如下兩種 delete from 表名 truncate table 表名 執行測試 我使用的是mysql待測試的表有20000條記錄,將其多拷兩份以備測試 分別執行兩個清空表的sql語句 從結果可以看出兩條語句都可以達到清空表的目的,而兩者的區別是 truncate的...

清空資料庫所有表資料

清空資料庫所有表資料 exec sp msforeachtable truncate table 查詢資料庫所有表名 select name from sysobjects where type u 游標 清空所有表資料 declare tablename varchar 50 declare sq...

清空SQL Server資料庫中所有表資料的方法

原文 清空sql server資料庫中所有表資料的方法 其實刪除資料庫中資料的方法並不複雜,為什麼我還要多此一舉呢,一是我這裡介紹的是刪除資料庫的所有資料,因為資料之間可能形成相互約束關係,刪除操作可能陷入死迴圈,二是這裡使用了微軟未正式公開的sp msforeachtable儲存過程。也許很多讀者...