› MySQL 5.5 Community Server
› MySQL 5.6 Community Server
› Percona Configuration Wizard
› XtraBackup 搭建主从复制
Great Sites on MySQL
› Percona
› MySQL Performance Blog
› Severalnines
推荐管理工具
› Sequel Pro
› phpMyAdmin
推荐书目
› MySQL Cookbook
MySQL 相关项目
› MariaDB
› Drizzle
参考文档
› http://mysql-python.sourceforge.net/MySQLdb.html
zhengfan2016
V2EX  ›  MySQL

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

  •  
  •   zhengfan2016 · Jul 9, 2021 · 3644 views
    This topic created in 1904 days ago, the information mentioned may be changed or developed.

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

    Supplement 1  ·  Jul 10, 2021

    感谢各位大佬,已解决😄Rzy0LF.png

    16 replies  •  2021-07-09 14:35:03 +08:00
    TomatoCLI
        1
    TomatoCLI  
       Jul 9, 2021
    六分钟过去了,你一个字段一个字段的改,估计都执行完了
    goxxoo
        2
    goxxoo  
       Jul 9, 2021
    我想笑 😂 真 Null 假 Null
    potatowish
        3
    potatowish  
       Jul 9, 2021 via iPhone
    实习生?
    usw
        4
    usw  
       Jul 9, 2021
    导成 cvs 手动批量替换再导回去(🤭
    cz5424
        5
    cz5424  
       Jul 9, 2021   ❤️ 1
    只能一个一个字段来,如果你字段太多随便写代码批量生产 sql

    update 字段=NULL where 字段='NULL'
    wangsipeng95
        6
    wangsipeng95  
       Jul 9, 2021
    哈哈哈 搁这真假美猴王呢😂
    zakokun
        7
    zakokun  
       Jul 9, 2021   ❤️ 1
    你把所有 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
        8
    zhengfan2016  
    OP
       Jul 9, 2021
    @cyrivlclth 有 50 多个表,每个表得有 10 到 20 个字段,一个一个打累死了
    zhengfan2016
        9
    zhengfan2016  
    OP
       Jul 9, 2021
    @potatowish 是的😂
    iikebug
        10
    iikebug  
       Jul 9, 2021
    查表 查字段 ,直接生成 sql 也用不了 10 分钟吧
    lovelive1024
        11
    lovelive1024  
       Jul 9, 2021
    数据不多的话可以直接导出,批量替换‘null’为 null,然后再导入
    lvgsnm
        12
    lvgsnm  
       Jul 9, 2021 via iPhone   ❤️ 1
    update table set field = NUll where field is null
    IGJacklove
        13
    IGJacklove  
       Jul 9, 2021 via Android   ❤️ 1
    写个脚本处理呗
    lllllliu
        14
    lllllliu  
       Jul 9, 2021   ❤️ 1
    isnull 有函数,
    lllllliu
        15
    lllllliu  
       Jul 9, 2021   ❤️ 1
    select * from testa where isnull(col);
    anzu
        16
    anzu  
       Jul 9, 2021   ❤️ 1
    MySql 有查询所有表名所有字段的语句,写脚本一个循环完事。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2529 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 53ms · UTC 01:35 · PVG 09:35 · LAX 18:35 · JFK 21:35
    ♥ Do have faith in what you're doing.