如何使用空值更新列

2022-01-17 00:00:00 sql-update mysql

我正在使用 mysql 并且需要使用空值更新列.我已经尝试了很多不同的方法,我得到的最好的方法是一个空字符串.

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 special syntax to do this?

推荐答案

无特殊语法:

CREATE TABLE your_table (some_id int, your_column varchar(100));

INSERT INTO your_table VALUES (1, 'Hello');

UPDATE your_table
SET    your_column = NULL
WHERE  some_id = 1;

SELECT * FROM your_table WHERE your_column IS NULL;
+---------+-------------+
| some_id | your_column |
+---------+-------------+
|       1 | NULL        |
+---------+-------------+
1 row in set (0.00 sec)

相关文章