-1

I'd like to know if mysql(or mariadb) offers a function for the expiration that a row can be removed automatically in the DB without using any extra scheduler program nor using any SQL like DELETE.

This should happen or define when you create a table so that once INSERT occurs it starts to manage it.

There are many related questions here:

MySQL how to make value expire?

Remove Mysql row after specified time

MySQL give rows a lifetime

However, I couldn't find the answer. I am not curious about using WHERE nor DELETE.

Is it even possible?

Andrey Nikolov
  • 12,967
  • 3
  • 20
  • 32
c-an
  • 3,543
  • 5
  • 35
  • 82
  • 1
    I think the closest thing to what you are looking for is creating an **Event** to remove old rows, just like someone explained in one of the links you posted. – Enrico Dias Dec 08 '18 at 05:47
  • @EnricoDias I don't want `the closest thing`. What I am looking for is `the thing`. – c-an Dec 08 '18 at 07:35
  • Why do you want this? – Strawberry Dec 08 '18 at 08:09
  • 2
    Short answer- No – P.Salmon Dec 08 '18 at 08:59
  • 1
    @Strawberry It can be used in some cases. For example, 'verification code'. Sometimes, we just need data for a single time and we don't need its log. And it should be removed in a certain time. – c-an Dec 08 '18 at 11:09
  • @ChanjungKim - What if the row went first into a "pending" table. Then if/when it was properly handled, it is moved to the 'real' table. ?? – Rick James Dec 08 '18 at 20:21
  • @RickJames, We can implement this kind of thing in many ways. I just want to know whether MySQL has the exact feature or not. And I guess the answer is no. – c-an Dec 09 '18 at 07:49
  • 1
    The answer is "No; MySQL does not have such a feature." Do you want a workaround? – Rick James Dec 09 '18 at 18:29

1 Answers1

0

Yes for same you can create an event by this way CREATE EVENT lifetime ON SCHEDULE EVERY 1 DAY STARTS '14:05:44' ENDS '14:05:46' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN // put your delete query here with where clause by calculate your exp date END

  • No, This is not the one I am asking. It is just creating an event. I don't want to create any events but giving an option to a row when I create a table like `auto_increment`. – c-an Dec 08 '18 at 11:12