Mysql删除所有行值为空的列 [英] Mysql Drop column where all row value is null
本文介绍了Mysql删除所有行值为空的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何删除所有值都为空的表中的所有列?
How can i drop all columns from a table where all its values are null ?
我有一个包含大约 20 多列的大表(100k+ 行),其中很多列根本没有使用,所以我想删除所有行中为 NULL 的所有列
i have a huge table (100k+ rows) with around 20+ columns, lots of these columns are not used at all, so i want to remove all columns that is NULL in all rows
推荐答案
您可以遍历游标中的每个字段并一举执行检查和ALTER
,或者您可以只运行一个检查一步以查看哪些字段未使用:
You could loop through each field in a cursor and perform the check and ALTER
in one fell swoop, or you can just run a check in one step to see which fields aren't used:
SELECT MAX(col1) col1
,MAX(col2) col2
,MAX(col3) col3
.....
FROM YourTable
然后删除 MAX()
为 NULL
的所有字段:
Then remove any fields that have a MAX()
of NULL
:
ALTER TABLE YourTable DROP col2
这篇关于Mysql删除所有行值为空的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文