Home  >  Q&A  >  body text

Can MySQL set a validity period for the value of a certain field?

I want to set a validity period of 10 minutes for the value of a certain field. After 10 minutes, it becomes Null. Does mysql have this function?

仅有的幸福仅有的幸福2710 days ago1289

reply all(4)I'll reply

  • 滿天的星座

    滿天的星座2017-05-18 10:56:45

    Just give a valid time field directly, and the code layer will make a logical judgment and give a null value after the validity period.

    reply
    0
  • PHPz

    PHPz2017-05-18 10:56:45

    You can write a trigger and change its status after the effective time

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-18 10:56:45

    Add two fields directly. In fact, you don’t need to change that field to null. You only need to judge the time at the logical level when using it. Mysql itself does not have this function

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-18 10:56:45

    It is recommended to use the logic code layer to handle it. After all, the database is only a function of accessing data, and these functions should not be mixed. By adding an additional creation time field, the code can determine whether it has expired.

    reply
    0
  • Cancelreply