How to update column with null value

前端 未结 13 652
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 05:08

I am using mysql and need to update a column with a null value. I have tried this many different ways and the best I have gotten is an empty string.

Is there a speci

13条回答
  •  情歌与酒
    2020-12-13 05:42

    Remember to look if your column can be null. You can do that using

    mysql> desc my_table;
    

    If your column cannot be null, when you set the value to null it will be the cast value to it.

    Here a example

    mysql> create table example ( age int not null, name varchar(100) not null );
    mysql> insert into example values ( null, "without num" ), ( 2 , null );
    mysql> select * from example;
    +-----+-------------+
    | age | name        |
    +-----+-------------+
    |   0 | without num |
    |   2 |             |
    +-----+-------------+
    2 rows in set (0.00 sec)
    
    mysql> select * from example where age is null or name is null;
    Empty set (0.00 sec)
    

提交回复
热议问题