I am maintaing a project. There is a table called ‘timeblock’, it has a field called ‘break_minutes’, in the legacy design, the type for ‘break_minutes’ is int, and default value is NULL.
This design is not good for my new task, because i will use ‘break_minutes’ to do some math functions. like sum. So i have already changed the database schema and the default value to 0 not Null.
So I have to change all the data whose ‘break_minutes’ value is NULL to 0.
So I write the sql:
update timeblock set break_minutes=0 where break_minutes=NULL
and the result is empty.
if I write sql like:
update timeblock set break_minutes=0 where break_minutes=NULL
the result is only for the rows whose value is 0.
Both two sqls can’t achieve my expectations.
Anyone who has the idea for that? thanks.
To check whether a value is NULL, use the special comparison predicates
IS NULLinstead of using comparison operators.Comparison operators return
unknownwhen comparing anything with NULL.