declare @tab varchar(20) while exists(select * from sysobjects where xtype='u') begin select top 1 @tab=name from sysobjects where xtype='u' exec('drop table '+@tab) end
MySQL数据库中,如果我们想清空数据表(删除数据表中所有内容)的话,可以通过下面两个语句来实现:
truncate table table_n;
delete from table_n;
实例
我们先通过实例看下通过这两种方式清空数据库的过程和结果
#delete演示
mysql> create table testforde(
-> number int not null auto_increment,
-> name varchar(20) not null,
一 清空数据库里所有的表 代码如下:DECLARE tablename varchar(50) DECLARE truncatesql varchar(255) DECLARE TrCun_Cursor CURSOR FOR select [name] from sysobjects where type = ‘U’ –有条件的清空表 name’不想清空的表名’– OPEN TrCun_Cursor FETCH TrCun_Cursor INTO tablename WHILE(fetch_s