简体   繁体   中英

Mysql int will not store non zero based null.

I can't seem to figure out how to get mysql to store an int value as 'null', instead it continues to give it a zero based value. In my case zero has a meaning to the app. Anybody know how I can store actual nulls?

I'm on my mobile phone so I can't test this... Also this is too long to be a comment... first thing try selecting the rows in question.. Then if they arent returned try updating a select when the rows are equal to 0.

Maybe it is null but you have a setting in mysql workbench that shows a 0 instead

SELECT id, field1 
FROM table 
WHERE field1 IS NULL;

If that doesn't return the rows then do this

SELECT id, field1
FROM table
WHERE field1 =0

If that does then try an update with these exact rows

UPDATE table t,
(   SELECT id, field1
    FROM table
    WHERE field1 = 0
) temp
SET t.field1 = NULL
WHERE t.id = temp.id

Hope that is helpful

You just write null :

mysql> CREATE TABLE t (i INT);
Query OK, 0 rows affected (0.15 sec)

mysql> INSERT INTO t VALUES (null);
Query OK, 1 row affected (0.09 sec)

mysql> SELECT * FROM t;
+------+
| i    |
+------+
| NULL |
+------+
1 row in set (0.00 sec)

mysql> SELECT * FROM t WHERE i IS NULL;
+------+
| i    |
+------+
| NULL |
+------+
1 row in set (0.03 sec)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM