MySQL通过表动态循环并根据条件删除行

时间:2014-10-16 14:44:08

标签: mysql

是否可以循环遍历表并根据条件删除行 我可以得到这样的所有表格:

SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'mytables'

是否可以遍历所有这些并执行与此类似的查询:

DELETE FROM table where NOW() > ColumnName 

1 个答案:

答案 0 :(得分:0)

循环选择表的语句,并为每个table_name执行:

BEGIN
    SET @s = CONCAT('DELETE FROM',table_name,' WHERE NOW() > ColumnName');
    PREPARE stmt FROM @s;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
END