一條 update 語句引起的事故,這回讓開發(fā)長(zhǎng)長(zhǎng)記性!!
點(diǎn)擊上方“碼農(nóng)突圍”,馬上關(guān)注 這里是碼農(nóng)充電第一站,回復(fù)“666”,獲取一份專屬大禮包 真愛,請(qǐng)?jiān)O(shè)置“星標(biāo)”或點(diǎn)個(gè)“在看

一、前言
二、過程
update tablename set source_name = "bj1062-北京市朝陽區(qū)常營(yíng)北辰福第"
where source_name = "-北京市朝陽區(qū)常營(yíng)北辰福第"
bj1062,是真的沒有錯(cuò)誤么?是的沒有錯(cuò)誤。開發(fā)執(zhí)行完成后,結(jié)果的確是符合預(yù)期。Harvey,我執(zhí)行了update,where條件都是對(duì)的,set的值也是對(duì)的,但是set后的字段全部都變成了0,你趕緊幫我看看,看看能不能恢復(fù)數(shù)據(jù)。


update tbl_name set str_col="xxx" = "yyy"
update tbl_name set (str_col="xxx" )= "yyy"
update tbl_name set str_col=("xxx" = "yyy")
select "xxx" = "yyy"
update tbl_name set str_col="xxx" = "yyy"
update tbl_name set str_col=0
mysql [localhost] {msandbox} (test) > select id,str_col from tbl_name where str_col="xxx" = "yyy";
+----+---------+
| id | str_col |
+----+---------+
| 1 | aaa |
| 2 | aaa |
| 3 | aaa |
| 4 | aaa |
+----+---------+
mysql [localhost] {msandbox} (test) > warnings
Show warnings enabled.
mysql [localhost] {msandbox} (test) > explain extended select id,str_col from tbl_name where str_col="xxx" = "yyy"\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: tbl_name
type: index
possible_keys: NULL
key: idx_str
key_len: 33
ref: NULL
rows: 4
filtered: 100.00
Extra: Using where; Using index
1 row in set, 1 warning (0.00 sec)
Note (Code 1003): /* select#1 */ select `test`.`tbl_name`.`id` AS `id`,`test`.`tbl_name`.`str_col` AS `str_col` from `test`.`tbl_name` where ((`test`.`tbl_name`.`str_col` = 'xxx') = 'yyy')
((`test`.`tbl_name`.`str_col` = 'xxx') = 'yyy')
mysql [localhost] {msandbox} (test) > select 'yyy'+0.0;
+-----------+
| 'yyy'+0.0 |
+-----------+
| 0 |
+-----------+
1 row in set, 1 warning (0.00 sec)
mysql [localhost] {msandbox} (test) > select 0=0;
+-----+
| 0=0 |
+-----+
| 1 |
+-----+
1 row in set (0.00 sec)
select id,str_col from tbl_name where 1=1;
三、小結(jié)
- END - 最近熱文
? “我辭退了一位學(xué)位學(xué)歷造假的程序員” ? 再見!杭州!再見!阿里巴巴! ? 面試官扎心一問: 為什么 ConcurrentHashMap 的讀操作不需要加鎖? ? Java這個(gè)高級(jí)特性,很多人還沒用過!
評(píng)論
圖片
表情
