Mysql中如何删除空白行?
我确实有一个包含超过 100000 个数据元素的表,但其中有近 350 个空白行。如何使用 phpmyadmin 删除这些空白行?手动删除是一项繁琐的任务。
I do have a table with more than 100000 data elements, but there are almost 350 blank rows within. How do I delete this blank rows using phpmyadmin? Manually deleting is a tedious task.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我正在 Windows 的命令提示符下执行 mysql 操作。基本查询:
并且
不起作用。我不知道它是否在
phpmyadmin
sqlcommand builder 中工作。无论如何:工作正常。
I am doing the
mysql
operation in command prompt in windows. And the basic queries:and
doesn't work. I don't know whether it works in
phpmyadmin
sqlcommand builder. Anyway:works fine.
我有一个 PHP 脚本,可以根据列数据类型自动删除空行。
这使我能够针对不同的列类型以不同的方式定义“空”。
例如,
由于“0”值在我的系统中没有意义,因此我将它们视为空。但我发现如果你这样做 (
first_name
= 0) 那么你总是会得到 true,因为在 MySQL 中字符串总是 == 0。所以我根据数据类型定制了“空”的定义。I have a PHP script that automatically removes empty rows based on column data types.
That allows me to define "emptiness" differently for different column types.
e.g.
Since "0" values are meaningless in my system, I count them as empty. But I found out that if you do (
first_name
= 0) then you will always get true, because strings always == 0 in MySQL. So I tailor the definition of "empty" to the data type.此过程将删除所有为空的列的任何行,忽略可能设置为 ID 的主列。我希望它对你有帮助。
像这样执行程序。
This procedure will delete any row for all columns that are null ignoring the primary column that may be set as an ID. I hope it helps you.
Execute the procedure like this.
我知道这个问题已经得到回答并且已经被勾选,但我为此编写了一个小函数,并认为它可能对其他人有用。
我使用数组调用函数,以便可以对不同的表使用相同的函数。
这是接受数组并构建删除字符串的函数
您可以将此函数用于多个表。您只需发送不同的表名称和数组即可工作。
我的函数将同时检查整行的空列或 NULL 列。如果您不需要它来检查 NULL,那么您可以删除该部分。
I know this has already been answered and has got a tick, but I wrote a small function for doing this, and thought it might be useful to other people.
I call my function with an array so that I can use the same function for different tables.
and here is the function which takes the array and builds the delete string
You can use this function for multiple tables. You just need to send in a different table name and array and it will work.
My function will check for a whole row of empty columns or NULL columns at the same time. If you don't need it to check for NULL then you can remove that part.
一般答案是:
或
参见:http://dev.mysql.com /doc/refman/5.0/en/delete.html
发布表格时会提供更多信息!~
另外,请务必执行以下操作:
在删除之前,以便您可以看到要删除的行!我认为在 phpMyAdmin 中您甚至可以只进行选择,然后“全选”并删除,但我不确定。这会非常快,而且非常安全。
The general answer is:
or
See: http://dev.mysql.com/doc/refman/5.0/en/delete.html
More info when you post your tables!~
Also, be sure to do:
before you delete, so you can see which rows you are deleting! I think in phpMyAdmin you can even just do the select and then "select all" and delete, but I'm not sure. This would be pretty fast, and very safe.