大佬们, sql 如何 update 所有字段的值=NULL where 所有字段='NULL'的时候

2021-07-09 11:27:42 +08:00
 zhengfan2016


如题,萌新把本地数据库搞坏了,现在有一堆真假 NULL 混在所有字段里,有没有什么办法一件替换啊

2157 次点击
所在节点    MySQL
16 条回复
cyrivlclth
2021-07-09 11:34:18 +08:00
六分钟过去了,你一个字段一个字段的改,估计都执行完了
goxxoo
2021-07-09 11:40:17 +08:00
我想笑 😂 真 Null 假 Null
potatowish
2021-07-09 11:42:00 +08:00
实习生?
usw
2021-07-09 11:43:28 +08:00
导成 cvs 手动批量替换再导回去(🤭
cz5424
2021-07-09 11:43:29 +08:00
只能一个一个字段来,如果你字段太多随便写代码批量生产 sql

update 字段=NULL where 字段='NULL'
wangsipeng95
2021-07-09 11:44:38 +08:00
哈哈哈 搁这真假美猴王呢😂
zakokun
2021-07-09 11:45:47 +08:00
你把所有 allow null 的字段名拿出来,写个脚本,组装成
update table set a=null where (a == "null");
update table set b=null where (b == "null");
update table set c=null where (c == "null");

就这样子咯
zhengfan2016
2021-07-09 11:49:44 +08:00
@cyrivlclth 有 50 多个表,每个表得有 10 到 20 个字段,一个一个打累死了
zhengfan2016
2021-07-09 11:50:00 +08:00
@potatowish 是的😂
iikebug
2021-07-09 11:51:57 +08:00
查表 查字段 ,直接生成 sql 也用不了 10 分钟吧
ily433664
2021-07-09 12:00:06 +08:00
数据不多的话可以直接导出,批量替换‘null’为 null,然后再导入
lvgsnm
2021-07-09 12:39:40 +08:00
update table set field = NUll where field is null
IGJacklove
2021-07-09 12:53:16 +08:00
写个脚本处理呗
lllllliu
2021-07-09 14:13:42 +08:00
isnull 有函数,
lllllliu
2021-07-09 14:16:43 +08:00
select * from testa where isnull(col);
anzu
2021-07-09 14:35:03 +08:00
MySql 有查询所有表名所有字段的语句,写脚本一个循环完事。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/788477

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX