0

How do I create a table in my schema using the current date or timestamp as the naming convention?

CREATE Table CURRENT_DATE|TIMESTAMP;
REPLACE CURRENT_DATE|TIMESTAMP
SELECT *
FROM other.othertable;
Alex
  • 16,739
  • 1
  • 28
  • 51
Reese
  • 21
  • 4

1 Answers1

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;
Reese
  • 21
  • 4