一段时间后从数据库中删除表

时间:2022-08-16 00:02:47

Is there any possibility of deleting a table from a database automatically, after a period of time?

经过一段时间后,是否有可能自动从数据库中删除表格?

If so, how is it achievable?

如果是这样,它是如何实现的?

1 个解决方案

#1


1  

You can use any sort of scheduler: https://dev.mysql.com/doc/refman/5.7/en/event-scheduler.html

您可以使用任何类型的调度程序:https://dev.mysql.com/doc/refman/5.7/en/event-scheduler.html

Just execute DROP table at that time.

只需在那时执行DROP表。

If there are more specific criteria, you could do any number of things, like dropping tables that have not had INSERTs or UPDATEs in a certain time (using a trigger to know when they are modified and keeping track of that in a table and then when that date is a certain age, DROP the table).

如果有更多特定条件,您可以执行任意数量的操作,例如删除在特定时间内没有INSERT或UPDATE的表(使用触发器知道它们何时被修改并在表中跟踪它然后何时那个日期是某个年龄,DROP表)。

This is kind of unusual, as tables tend to not be DROPped, normally data is selectively DELETEd in archive processes but the table sticks around.

这有点不寻常,因为表往往不是DROPped,通常数据在归档过程中有选择地DELETEd但表格仍然存在。

#1


1  

You can use any sort of scheduler: https://dev.mysql.com/doc/refman/5.7/en/event-scheduler.html

您可以使用任何类型的调度程序:https://dev.mysql.com/doc/refman/5.7/en/event-scheduler.html

Just execute DROP table at that time.

只需在那时执行DROP表。

If there are more specific criteria, you could do any number of things, like dropping tables that have not had INSERTs or UPDATEs in a certain time (using a trigger to know when they are modified and keeping track of that in a table and then when that date is a certain age, DROP the table).

如果有更多特定条件,您可以执行任意数量的操作,例如删除在特定时间内没有INSERT或UPDATE的表(使用触发器知道它们何时被修改并在表中跟踪它然后何时那个日期是某个年龄,DROP表)。

This is kind of unusual, as tables tend to not be DROPped, normally data is selectively DELETEd in archive processes but the table sticks around.

这有点不寻常,因为表往往不是DROPped,通常数据在归档过程中有选择地DELETEd但表格仍然存在。