close

[Solved] 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

Hello Guys, How are you all? Hope You all Are Fine. Today I am trying to update one column in my table but unfortunetly I am facing following error: 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 in Mysql. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How 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 Error Occurs ?

I am trying to update one column in my table but unfortunetly I am facing following error.

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

How To Solve 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 Error ?

  1. How To Solve 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 Error ?

    To Solve 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 Error I Think Your SQL_SAFE_UPDATES is setted thats why You cant update or delete records without specifying a primary key So that Just try to set SQL_SAFE_UPDATES = 0 Just run this SQL Query: SET SQL_SAFE_UPDATES = 0; Then Run Your query For Example my query is: UPDATE tablename SET columnname=1; It will run successfully, But If you want to set SQL_SAFE_UPDATES to as it was then run this query: SET SQL_SAFE_UPDATES=1; Now, Your error must be solved.

  2. 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

    To Solve 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 Error You need to Use Primary Key in Your Query. If You are using without primary key then You should face above error: UPDATE customers SET country_code = '+91' WHERE country = 'India'; // It Will Give You Error But If You are using Primary Key then You will no longer face any error. Here in Query customer_id is my primary key: UPDATE customers SET country_code = '+91' WHERE (country = 'INdia' AND customer_id <> 0); // It will Run Successfully Now, Your error must be solved.

Solution 1: set SQL_SAFE_UPDATES = 0

I Think Your SQL_SAFE_UPDATES is setted thats why You cant update or delete records without specifying a primary key So that Just try to set SQL_SAFE_UPDATES = 0 Just run this SQL Query.

SET SQL_SAFE_UPDATES = 0;

Then Run Your query For Example my query is.

UPDATE tablename SET columnname=1;

It will run successfully, But If you want to set SQL_SAFE_UPDATES to as it was then run this query.

SET SQL_SAFE_UPDATES=1;

Now, Your error must be solved.

Solution 2: Use Primary Key

You need to Use Primary Key in Your Query. If You are using without primary key then You should face above error.

UPDATE customers SET country_code = '+91' WHERE country = 'India';  // It Will Give You Error

But If You are using Primary Key then You will no longer face any error. Here in Query customer_id is my primary key.

UPDATE customers SET country_code = '+91' WHERE (country = 'INdia' AND customer_id <> 0); // It will Run Successfully

Now, Your error must be solved.

Summary

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

Leave a Comment