MySQL, you is using Safe update mode

Source: Internet
Author: User

The MySQL default mode is Sql_safe_updates=1. In this mode, regardless of whether you are an update or delete row, the Where condition specifies the primary key. An error occurs if the Where condition only appears if it is not a primary key.

Example:

Set sql_safe_updates =1;--Start security update, this is the premise of my example.

--Step One: Build two tables

CREATE table t (x int,y int);

CREATE table t2 (x int primary key,y int);

--Step two: Insert data into the table

INSERT into t (x, Y) VALUES (2,2), (3,3);

INSERT into T2 (x, y) VALUES (2,2), (3,3);

--Step Three: test the effect of the security update mode on the update delete.

Update T set y =100 where x=1;--this will give an error, you are using Safe update mode ...

Update T2 set y=100 where x=1;--this is nothing. Because X is the primary key in this table T2, it is not in table T.

--Solutions:

In order to update the T-table can also be done, we need to add a sentence before the UPDATE statement.

Set Sql_safe_updates =0;--Disable this mode is possible .

MySQL, you is using Safe update mode

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.