• MySQL sql_safe_updates 分析


    我在练习MySQL操作语句时,使用一条完全没有错误的语句:

    update students set name='drake' where name='chuan';

    却报了如下错误:

    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 -> SQL Queries and reconnect.
    简单翻译一下:
    你正在使用 安全更新模式(safe upate mode)并且你在尝试 update 一个表时 没有用带有键的列 作为where条件,在首选项中切换选项。

    初学者在修改一个值时可能会用以下语句:

    update t set col='new_value' 

    而这正是很多人常犯的错误。因为他没有限定条件,会将表中所有的记录都修改一遍。

    为了防止这种错误出现,我们可以开启安全更新模式(safe update mode)

    set [global] SQL_SAFE_UPDATES = 1;

    update操作中:当where条件中列(column没有索引可用且无limit限制时会拒绝更新。where条件为常量且无limit限制时会拒绝更新。

    delete操作中: 当①where条件为常量,where条件为空,③或where条件中 列(column没有索引可用且无limit限制时拒绝删除。

    需要注意的是:

    update操作中,where可以为常量  ,where条件中列(column)可以没有索引。但是需要有limit限制。

    然而delete要严格一些:where不能为常量,且where条件中列(column)不能没有索引!

  • 相关阅读:
    TestCase NotePad3.0 of robotium
    一些小的东东
    面试ASP.NET程序员的笔试题和机试题
    verify the text views its easy to use getView from the adapter
    巧用Cacls.exe命令来修改文件访问控制权限
    Monkey test
    monkeyrunner test
    Autotest NotePad with robotium
    网站新技术知识
    序列化
  • 原文地址:https://www.cnblogs.com/drake-guo/p/6101531.html
Copyright © 2020-2023  润新知