【发布时间】:2013-07-08 14:05:24
【问题描述】:
我在 MySQL 中有一个名为 word 的只插入表。一旦行数超过1000000,我想删除表的前100000行。
我在python中使用mysqldb,所以我有一个全局变量:
wordcount = cursor.execute("select * from word")
将返回python环境中表的行数。然后,每次插入新行时,我都会将 wordcount 增加 1。然后我检查行数是否大于1000000,如果是,我想删除前100000行:
if wordcount > 1000000:
cursor.execute("delete from word limit 100000")
我从这个帖子中得到了这个想法: Delete first X lines of a database
但是,这条 SQL 以删除我的 ENTIRE 表结束,我在这里缺少什么?
谢谢。
【问题讨论】:
-
你确定
wordcount = cursor.execute("select * from word")返回记录数? -
在python环境下是,在MySQL下不行。例如 wordcount = cursor.execute("select count(*) from word") 在 python 中会返回 1,因为它是 1 行。而我的 SQL 将返回行数(在 python 环境中),即计数
-
你读过
cursordoc吗? -
是的。我最想知道为什么我的 sql 删除整个表而不是前 100000 行
-
在此处查找获取行数的示例:stackoverflow.com/questions/2511679/…