mysql的动态表名

  1. create EVENT createMtpulseTable
    ON SCHEDULE every 1 month 
    STARTS CURRENT_TIMESTAMP
    DO
    CALL pro_createTable();
    
    CREATE PROCEDURE pro_createTable()
    BEGIN
    DECLARE str VARCHAR(500);
    -- set @str='create table';
    set str= CONCAT('create table mtpulse',DATE_FORMAT(CURRENT_DATE(),'%Y%m'),'(id INT not NULL  auto_increment,PRIMARY KEY(id))');
    SET @sqlstr=str;
    PREPARE stmt from @sqlstr;
    EXECUTE stmt;
    deallocate prepare stmt;
    END;
posted @ 2019-12-22 17:39  那些年的代码  阅读(2505)  评论(0编辑  收藏  举报