2017-04-03 4 views
0

現在の日付またはタイムスタンプを命名規則として使用して、スキーマ内にテーブルを作成するにはどうすればよいですか?MySQLテーブル作成規則

CREATE Table CURRENT_DATE|TIMESTAMP; 
REPLACE CURRENT_DATE|TIMESTAMP 
SELECT * 
FROM other.othertable; 

答えて

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;