2 つのテーブル A と B があり、両方のテーブルが同じです。今日、テーブル A にいくつかの値を挿入し、挿入されたすべてのテーブル A のデータを 2 日後にテーブル B に自動挿入したい場合。たとえば、今日は 2013 年 6 月 15 日で、テーブル A のすべてのデータは 2013 年 6 月 17 日に自動的にシフトされます。
スクリプトを教えてください。
前もって感謝します。
You'll need to add a timestamp field to your rows in Table A, then you can do this:
insert into b (select * from A where datediff(curdate(), postdate)>=2)
where postdate is your timestamp.
To automate this you can use the mySQL event scheduler (see CREATE EVENT for the syntax) if it's enabled on your server, or use a cron job as suggested elsewhere
insert into tableb select * from tablea;
完全なドキュメントはこちら
多分あなたは次のようなものを探しています:
CREATE TABLE tableB LIKE tableA;
すでに述べたように、これの SQL コードは「insert into b (select * from A)」です。
これを自動的に呼び出すには、小さな PHP-Cronjob を作成し、これをサーバーの crontab に追加して、x 分/時間/日ごとに実行させます (必要なもの)。