如何添加日期到MySQL表名? [英] How to add date to MySQL table name?
问题描述
查询需要创建一个像现有表的表。
只有它必须添加一天后的日期(无分离)到tablename。
我已经提出了这个解决方案:
代码到明天的日期:
$ date = date('dmY');
$ date = strtotime(date(dmY,strtotime($ date))。+1 day);
查询:
$ queryvc =CREATE TABLE vervanger $ date LIKE vervanger;
INSERT vervanger $ date SELECT * FROM vervanger;
当我在php中回应这个信息时,它会给出我想要的结果。但查询不执行。而且我认为这是因为我不会从通常必须的查询中删除$ date。有没有人可以解决这个问题?
查询将每周运行一次cronjob。但是在cronjob中,所有超过几个月的日期表都将被删除。
提前谢谢!
- 首先创建归档数据库(vervanger_archive)。
- 如果您没有设置DATE_ADD(为每行添加时间戳),则以原始
为基数。 - 第3 SET 1 cron任务一天中将OLD行从原始
表移动到归档表。
创建具有时间戳名称的表是不好的选择..
I am now writing some query's for a cronjob. The query's need to create a table like an existing table. Only it has to add the date of the day after(without separations) to the tablename.
I have come up with this solution: Code to date of tomorrow:
$date = date ('dmY');
$date = strtotime(date("dmY", strtotime($date)) . " +1 day");
The query:
$queryvc = "CREATE TABLE vervanger$date LIKE vervanger;
INSERT vervanger$date SELECT * FROM vervanger";
When i echo this in php it gives the result i want. But the query doesn't execute. And I think it is because of the fact that i do not 'cut out' the $date from the query wich is normally a must. Does anyone have a solution to this?
The query will be run once a week with a cronjob. But in the cronjob all tables with dates more than few months back will also be deleted. That way the database will not grow TO big.
thanks in advance!
- 1st create archive database (vervanger_archive) .
- 2nd at original base if you dont have set DATE_ADD (adding timestamp for each row).
- 3rd SET 1 cron task once upon a day to move OLD rows from Original table to the archive table.
Creating tables with timestamp names is bad choice..
这篇关于如何添加日期到MySQL表名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!