drkj41932 2012-06-23 00:18
浏览 405

是否可以在mysql中为表设置过期日期/时间?

I'm wondering if it is possible to set an "Expire" time or date when creating a table in mysql.

For example a table is created and will expire/auto-delete in 2 hours. Something to that effect. Google didn't give any answer so its probably not as simple as I'm hoping.

Need: I'm making a site with cart functionality. Users can add items to the cart if they are not signed in. This info is stored in a temp table that will then be migrated to a specific users table or orders once they log in. Well I was trying to find a way to remove the temporary table if say the user never signs in or completes an order and then leaves the site permanently. That way I wouldn't end up with a bunch of temporary tables cluttering things up.

  • 写回答

2条回答 默认 最新

  • duanluo5096 2012-06-23 00:29
    关注

    You are doing it wrong! It's almost always an error when you change your schema dynamically. You should add and remove rows, not tables.

    Put all your orders in the same table and just timestamp them. You can have a field with order status and remove non-completed orders with a DELETE ... WHERE status='not completed' AND timefield < DATE_SUB(NOW(), INTERVAL 2 HOUR), or you can put temporary orders in another table than completed orders, but all temp orders should go to the same table.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题