I have a very large table with two INT columns that are null on Default. This is a problem because since they are INT fields, it would help in many cases if they were originally set to 0.
So my questions are, is there a way I can UPDATE and INCREMENT(+1) these fields while they are like this (null on Default)? BTW.. I didn't have luck so far, it seems increment only works when the default=0
..or is my only option to Change the Default to none from null
You can insert NULL value into an int column with a condition i.e. the column must not have NOT NULL constraints.
Syntax for MySQLMySQL uses the AUTO_INCREMENT keyword to perform an auto-increment feature. By default, the starting value for AUTO_INCREMENT is 1, and it will increment by 1 for each new record. VALUES ('Lars','Monsen'); The SQL statement above would insert a new record into the "Persons" table.
But the short answer is: yes, int columns can have NULL values.
UPDATE TableName SET column = IFNULL(column, 0) + 1 WHERE ...
More info on IFNULL. It returns the first argument if it is not NULL, the second otherwise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With