How do I delete blank rows in Mysql?

前端 未结 5 1119
忘了有多久
忘了有多久 2021-02-07 18:30

I do have a table with more than 100000 data elements, but there are almost 350 blank rows within. How do I delete this blank rows using phpmyadmin? Manually deleting is a tedio

5条回答
  •  梦如初夏
    2021-02-07 18:49

    This procedure will delete any row for all columns that are null ignoring the primary column that may be set as an ID. I hope it helps you.

    DELIMITER //
    CREATE PROCEDURE DeleteRowsAllColNull(IN tbl VARCHAR(64))
    BEGIN
    SET @tbl = tbl;
    SET SESSION group_concat_max_len = 1000000;
    SELECT CONCAT('DELETE FROM `',@tbl,'` WHERE ',(REPLACE(group_concat(concat('`',COLUMN_NAME, '` is NULL')),',',' AND ')),';') FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = @tbl AND COLUMN_KEY NOT LIKE 'PRI' into @delete_all;
    PREPARE delete_all FROM @delete_all;
    EXECUTE delete_all;
    DEALLOCATE PREPARE delete_all;
    END //
    DELIMITER ;
    

    Execute the procedure like this.

    CALL DeleteRowsAllColNull('your table');
    

提交回复
热议问题