久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <i id='j4WOn'><tr id='j4WOn'><dt id='j4WOn'><q id='j4WOn'><span id='j4WOn'><b id='j4WOn'><form id='j4WOn'><ins id='j4WOn'></ins><ul id='j4WOn'></ul><sub id='j4WOn'></sub></form><legend id='j4WOn'></legend><bdo id='j4WOn'><pre id='j4WOn'><center id='j4WOn'></center></pre></bdo></b><th id='j4WOn'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='j4WOn'><tfoot id='j4WOn'></tfoot><dl id='j4WOn'><fieldset id='j4WOn'></fieldset></dl></div>
    • <bdo id='j4WOn'></bdo><ul id='j4WOn'></ul>
  • <small id='j4WOn'></small><noframes id='j4WOn'>

    <legend id='j4WOn'><style id='j4WOn'><dir id='j4WOn'><q id='j4WOn'></q></dir></style></legend>

        <tfoot id='j4WOn'></tfoot>

        將行從 TableA 移動到 Table-Archive

        Move rows from TableA into Table-Archive(將行從 TableA 移動到 Table-Archive)
        <i id='4fTZL'><tr id='4fTZL'><dt id='4fTZL'><q id='4fTZL'><span id='4fTZL'><b id='4fTZL'><form id='4fTZL'><ins id='4fTZL'></ins><ul id='4fTZL'></ul><sub id='4fTZL'></sub></form><legend id='4fTZL'></legend><bdo id='4fTZL'><pre id='4fTZL'><center id='4fTZL'></center></pre></bdo></b><th id='4fTZL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4fTZL'><tfoot id='4fTZL'></tfoot><dl id='4fTZL'><fieldset id='4fTZL'></fieldset></dl></div>

            <bdo id='4fTZL'></bdo><ul id='4fTZL'></ul>
          • <legend id='4fTZL'><style id='4fTZL'><dir id='4fTZL'><q id='4fTZL'></q></dir></style></legend>

                <tfoot id='4fTZL'></tfoot>

                <small id='4fTZL'></small><noframes id='4fTZL'>

                    <tbody id='4fTZL'></tbody>
                  本文介紹了將行從 TableA 移動到 Table-Archive的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  是否可以每周在 mysql 表中自動將 3 天前的行移動到另一個名為Table_Archive"的表中?

                  Is it possible to move rows that are 3 days old into an other table called "Table_Archive" automatically in mysql ones a week?

                  表A例如:

                  ID | stringvalue | Timestamp
                  1  | abc         | 2011-10-01
                  2  | abc2        | 2011-10-02
                  3  | abc3        | 2011-10-05
                  4  | abc4        | 2011-10-10
                  5  | abc5        | 2011-10-11
                  

                  搬家后

                  表A:

                  ID | stringvalue | Timestamp
                  4  | abc4        | 2011-10-10
                  5  | abc5        | 2011-10-11
                  

                  表_檔案:

                  ID | stringvalue | Timestamp
                  1  | abc         | 2011-10-01
                  2  | abc2        | 2011-10-02
                  3  | abc3        | 2011-10-05
                  

                  當新的輸入進入tableA時,下一步的ID(PK)不會有任何問題嗎?

                  And when new input comes into tableA it wont be any problems with ID (PK) in the next move?

                  我得到了什么:

                  CREATE PROCEDURE clean_tables ()
                  BEGIN
                      BEGIN TRANSACTION;
                  
                      DECLARE _now DATETIME;
                      SET _now := NOW();
                  
                      INSERT
                      INTO    Table_Archive
                      SELECT  *
                      FROM    TableA
                      WHERE   timestamp < _now - 3;
                      FOR UPDATE;
                  
                      DELETE
                      FROM    TableA
                      WHERE   timestamp < _now - 3;
                  
                      COMMIT;
                  END
                  

                  如何將 _now 更改為 3 天前的日期?

                  How do I change _now to be the date 3 days ago?

                  推薦答案

                  就個人而言,我會使用 MySQL 事件調度程序.這是一個內置的事件調度器,類似于 Linux 中的 CRON.

                  Personally, I would make use of the MySQL Event Scheduler. This is a built in event scheduler rather like CRON in Linux.

                  您可以指定它以指定的時間間隔調用一個過程、過程或函數或運行一些 SQL.

                  You can specify it to call a procedure, procedures or functions or run a bit of SQL at designated intervals.

                  閱讀 MySQL 文檔,但一個例子是:

                  Read the MySQL docs but an example would be:

                  CREATE EVENT mydatabase.myevent
                  ON SCHEDULE EVERY 1 WEEK STARTS CURRENT_TIMESTAMP + INTERVAL 10 MINUTE
                  DO
                   call clean_tables();
                  

                  所以這是說每周調用一次 clean_tables() 并在 10 分鐘后進行第一次調用"

                  So this is saying "call clean_tables() once a week and make the first call in 10 minutes' time"

                  一個問題是(我認為)默認情況下禁用了事件調度程序.要打開它運行:

                  One gotcha is that the event scheduler is (I think) disabled by default. To turn it on run:

                  SET GLOBAL event_scheduler = ON;
                  

                  然后您可以運行:

                  SHOW PROCESSLIST;
                  

                  查看事件調度程序線程是否正在運行.

                  To see whether the event scheduler thread is running.

                  至于保留您的表 A ID 列(如果必須).我會將 Table_Archive 上的 ID 保留為該表的唯一標識,即使其成為主鍵 &auto_increment 然后有一個 'Original_TableA_ID' 列來存儲 TableA ID.如果需要,您可以在其上放置唯一索引.

                  As for preserving your Table A ID column (if you must). I would keep the ID on Table_Archive as unique to that table i.e make it the primary key & auto_increment and then have a 'Original_TableA_ID' column in which to store the TableA ID. You can put a unique index on this if you want.

                  所以 Table_Archive 應該是這樣的:

                  So Table_Archive would be like:

                  create table `Table_Archive` (
                  ID int unsigned primary key auto_increment, -- < primary key auto increment
                  tableAId unsigned int not null, -- < id column from TableA
                  stringValue varchar(100),
                  timestamp datetime,
                  UNIQUE KEY `archiveUidx1` (`tableAId`) -- < maintain uniqueness of TableA.ID column in Archive table
                  );
                  

                  似乎沒有人回答您最初的問題如何將 _now 更改為 3 天前的日期?".您可以使用 INTERVAL 來做到這一點:

                  Nobody seems to have answered your original question "How do I change _now to be the date 3 days ago?". You do that using INTERVAL:

                  DELIMITER $
                  
                  CREATE PROCEDURE clean_tables ()
                  BEGIN
                  BEGIN TRANSACTION;
                  
                  DECLARE _now DATETIME;
                  SET _now := NOW();
                  
                  INSERT
                  INTO    Table_Archive
                  SELECT  *
                  FROM    TableA
                  WHERE   timestamp < _now - interval 3 day;
                  FOR UPDATE;
                  
                  DELETE
                  FROM    TableA
                  WHERE   timestamp < _now - interval 3 day;
                  
                  COMMIT;
                  END$
                  
                  DELIMITER ;
                  

                  最后一點是,您應該考慮在 TableA 的時間戳列上創建索引,以提高 clean_tables() 過程的性能.

                  One final point is that you should consider creating an index on the timestamp column on TableA to improve the performance of you clean_tables() procedure.

                  這篇關于將行從 TableA 移動到 Table-Archive的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數根據 N 個先前值來決定接下來的 N 個行)
                  reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達式的結果;條款?)
                  Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數的 ignore 選項是忽略整個事務還是只是有問題的行?) - IT屋-程序員軟件開發技
                  Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環數組)
                  pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調用 o23.load 時發生錯誤 沒有合適的驅動程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數據庫表作為 Spark 數據幀讀取?)
                  <tfoot id='WbvAT'></tfoot>

                  <small id='WbvAT'></small><noframes id='WbvAT'>

                    <legend id='WbvAT'><style id='WbvAT'><dir id='WbvAT'><q id='WbvAT'></q></dir></style></legend>

                    <i id='WbvAT'><tr id='WbvAT'><dt id='WbvAT'><q id='WbvAT'><span id='WbvAT'><b id='WbvAT'><form id='WbvAT'><ins id='WbvAT'></ins><ul id='WbvAT'></ul><sub id='WbvAT'></sub></form><legend id='WbvAT'></legend><bdo id='WbvAT'><pre id='WbvAT'><center id='WbvAT'></center></pre></bdo></b><th id='WbvAT'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='WbvAT'><tfoot id='WbvAT'></tfoot><dl id='WbvAT'><fieldset id='WbvAT'></fieldset></dl></div>
                        <tbody id='WbvAT'></tbody>

                          <bdo id='WbvAT'></bdo><ul id='WbvAT'></ul>
                          • 主站蜘蛛池模板: 九九精品在线 | 成人国产午夜在线观看 | 亚洲国产精品一区二区久久 | 日韩中文字幕在线免费 | 国产精品视频一区二区三区不卡 | 亚洲日本中文字幕在线 | 在线三级网址 | 国产日韩精品视频 | 日韩在线免费视频 | 精品国产精品一区二区夜夜嗨 | 午夜在线小视频 | 日日操夜夜操天天操 | 99成人| 久久99国产精一区二区三区 | 91一区 | 国产成人综合av | 91在线最新 | 一区二区中文字幕 | 国产黄色网址在线观看 | 综合久久99| 国产精品久久久久久久久久久久午夜片 | 国产亚洲精品久久久优势 | 91在线色视频 | 中文字幕av一区 | 久久精品国产一区二区电影 | 欧美精品在线一区二区三区 | 久久久人成影片一区二区三区 | 日本在线视频中文字幕 | 色欧美综合 | 蜜桃黄网| 久久精品免费观看 | 精品日韩在线 | 91久久北条麻妃一区二区三区 | 色黄爽 | gogo肉体亚洲高清在线视 | 国产精品久久久久久久久久免费 | 91一区二区 | www.日本在线观看 | 日韩欧美在线一区二区 | 欧美成人精品一区二区男人看 | 国产精品永久久久久久久www |