MySQL give rows a lifetime

后端 未结 3 2021
傲寒
傲寒 2020-12-22 06:25

How can I create a lifetime of a row so after a specific time say 2 weeks the row will automatically erase? Any info would be great.

3条回答
  •  庸人自扰
    2020-12-22 06:41

    RDBMS don't generally allow rows to automatically self destruct. It's bad for business.

    More seriously, some ideas, depending on your exact needs

    • run a scheduled job to run a DELETE to remove rows based on some date/time column
    • (more complex idea) use a partitioned table with a sliding window to move older rows to another partition
    • use a view to only show rows less than 2 weeks old

提交回复
热议问题