gpt4 book ai didi

mysql - 如何限制mysql表中每个用户有1000条记录

转载 作者:行者123 更新时间:2023-11-29 08:36:14 24 4
gpt4 key购买 nike

我有 1,000,000 个用户,我想存储用户最新的 1000 条历史记录。

所以我想将我们的数据限制为 1,000,000 * 1000,并且我将使用用户 id 创建多个表。

而且我有更多的用户,我不想在后台扫描每个用户的记录限制,我认为这很丑陋。

有一些功能:

  • The table is store user's history
  • Limit every user only has 1000 rows in table
  • If user's new data to insert a row, discard the oldest row
  • Always 1000, allow non-real-time
  • 1,000,000 users
  • It's sociable, insert speed must fast.

最佳答案

创建一个触发器,在插入新行时将截断最旧的行。

http://dev.mysql.com/doc/refman/5.5/en/triggers.html

关于mysql - 如何限制mysql表中每个用户有1000条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15133009/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com