mysql (5.1) > create table with name from a variable

前端 未结 2 1040
庸人自扰
庸人自扰 2021-01-01 23:28

I\'m trying to create a table with a name based on the current year and month(2011-09), but MySQL doesn\'t seem to like this.

SET @yyyy_mm=Year(         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-01 23:42

    set @yyyy_mm=concat(year(now()),'-',month(now()));
    set @str = concat('create table survery.`', @yyyy_mm,'` like survey.interim;');
    prepare stmt from @str;
    execute stmt;
    deallocate prepare stmt;
    

提交回复
热议问题