如何使用当前日期或时间戳作为命名约定在我的架构中创建表?
CREATE Table CURRENT_DATE|TIMESTAMP;
REPLACE CURRENT_DATE|TIMESTAMP
SELECT *
FROM other.othertable;
答案 0 :(得分:0)
I managed to solve it, for those interested.
SET @YYYY_MM_DD_HH_MM_SS=date_format((SELECT NOW() FROM DUAL),'%Y-%m-%d %h:%m:%s');
SET @c = CONCAT('CREATE TABLE `new`.`',@YYYY_MM_DD_HH_MM_SS, '` LIKE `old`.`oldtable`');
PREPARE stmt from @c;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @u = concat('REPLACE `new`.`',@YYYY_MM_DD_HH_MM_SS, '` SELECT * FROM `old`.`oldtable`');
PREPARE stmt2 from @u;
EXECUTE stmt2;
DEALLOCATE PREPARE stmt2;