MySQL give rows a lifetime

后端 未结 3 2030
傲寒
傲寒 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:44

    Or you can add timestamp column and always select like this:

    SELECT * FROM myTable WHERE timetampColumn>=date_sub(now(), interval 2 week);
    

    It is better if you don't need to erase the data and you want to show only data from last 2 weeks.

提交回复
热议问题