How can I delete the contents of all tables in my database in phpMyAdmin without dropping the database?

后端 未结 10 1389
予麋鹿
予麋鹿 2021-02-13 03:32

How can I empty the contents of all tables in my database in phpMyAdmin without dropping any of the tables in the database?

Since I do this several times an hour while i

10条回答
  •  青春惊慌失措
    2021-02-13 03:59

    drop procedure if exists truncate_tables;
    
    delimiter #
    create procedure truncate_tables()
    begin
     declare tab_name varchar(64);
     declare done tinyint unsigned default 0;
    
     declare table_cur cursor for select t.table_name
     from 
      information_schema.schemata s
      inner join information_schema.tables t on s.schema_name = t.table_schema
     where
       s.schema_name = database() and t.table_type = 'BASE TABLE';
    
     declare continue handler for not found set done = 1;
    
     open table_cur;
     repeat
       fetch table_cur into tab_name;
       set @cmd = concat('truncate table ', tab_name);
    
       prepare stmt from @cmd;
       execute stmt;
     until done end repeat;
    
     close table_cur;
    end #
    

提交回复
热议问题