更新數據庫中數據時出現: Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences 問題


使用workbench在數據庫中更新數據時報錯: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column  To disable safe mode, toggle the option in Preferences(錯誤及操作見截圖)

1.sql:   update tableName set employee_detailed_status='xx', employee_status_code='xx' where employee_detailed_status='xx'

 

2.通過錯誤提示可以看出:  當前數據庫使用的是 safe update mode(安全更新模式),並且在update時where 中沒有把主鍵當做條件。因為在該模式會導致非主鍵條件下無法執行update或者delete命令,因此會報錯。

3.如何解決這個問題呢?

第一種方法:

執行命令SET SQL_SAFE_UPDATES = 0 來修改下數據庫模式,這樣再去執行update語句或者delete語句即可成功。

參考地址: https://jingyan.baidu.com/article/6c67b1d6f0efca2787bb1eba.html

 

第二種方法:

  (1) 在workbench的菜單欄點擊“edit-->Preferences”,然后會彈出對話框“workbench preferences”。

  

 

  (2) 在“workbench”左邊欄點擊“SQL Editor”,會看到最后一行是“Safe Updates……”是打鈎的,我們只要缺消打鈎即可。

       當缺消打鈎之后,點擊“OK”按鈕,linux系統可能會出現“OK”按鈕無法點擊的情況,請在左邊欄點擊“General Editors”選項,這樣就可以點擊“OK”按鈕了。

  

 

  (3) 當上面設置好之后,請重啟workbench。

 

參考地址: https://jingyan.baidu.com/article/6c67b1d6f0efca2787bb1eba.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM