create table mytablename.now()的语法是什么?

时间:2012-02-07 10:16:00

标签: mysql

我想创建一个表并将NOW()追加到表名的末尾。 会是什么语法?

哎呀谢谢你的纠正。

我之所以这样做是因为我每天都有一个在数据库表上运行的脚本。如果满足某些条件,我将从主表中删除。但是在删除之前我只想通过运行来创建备份副本:create table rc_profile_backup_table_NOW(),如rc_profile_table;

然后我运行:从rc_profile_table中插入rc_profile_table_backup_NOW()select *

希望这更好。 感谢

1 个答案:

答案 0 :(得分:1)

使用预处理语句,这是一种相当丑陋的方法。您可以调整“now”部分,因为现在我认为会生成无效的表名。

set @c=concat('create table zogi_',date_format(now(),'%Y_%m_%d'),' (a varchar(10))');
prepare stmt from @c;
execute stmt;
deallocate prepare stmt

describe zogi_2012_02_07;

它创建一个名为zogi_ [year] [month] [day]的表。