I'm trying to modify the value of the column in mysql column, but it doesn't work

Asked 2 years ago, Updated 2 years ago, 30 views

I'm trying to modify the value of the column, but it doesn't work.

desc bbs;
+--------------+---------------+------+-----+---------+-------+
| | Field        | Type          | Null | Key | Default | Extra |
+--------------+---------------+------+-----+---------+-------+
| | bbsID        | int           | NO   | PRI | NULL    |       |
| | bbsTitle     | varchar(20)   | YES  |     | NULL    |       |
| | userID       | varchar(20)   | YES  |     | NULL    |       |
| | bbsDate      | datetime      | YES  |     | NULL    |       |
| | bbsContent   | varchar(2048) | YES  |     | NULL    |       |
| | bbsAvailable | int           | YES  |     | NULL    |       |
| | count        | int           | YES  |     | NULL    |       |
+--------------+---------------+------+-----+---------+-------+

Here, the value of the count column is

mysql> update bbs set count = count+10 where bbsID=1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0 

I modified it to (I heard it was successful)
If you select it, it says null.

mysql> select userID, count from bbs where bbsID = 1;
+---------+-------+
| | userID  | count |
+---------+-------+
| | gildong |  NULL |
+---------+-------+
1 row in set (0.00 sec)

What's wrong with this?

mysql

2022-09-20 19:08

1 Answers

Because Null + 1 is null! Null cannot be added. It's a dangerous idea that the numeric field is null with no default.

It will probably work if you do .

update bbs
set count = ifnull(count, 0) + 10
where bbsID = 1;


2022-09-20 19:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.