Reputation: 7788
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?
Upvotes: 0
Views: 130
Reputation: 311393
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)
Upvotes: 1
Reputation: 25842
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
Upvotes: 2