Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does MySQL think that I'm not using a WHERE statement?

I'm trying to update a table called rep in a database called premier_products. The table's primary key is rep_num.

When I run the following statement:

update rep 
set last_name = "Perry"
where rep_num = 85;

I get an error that says "You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column."

I Googled that error message and most of the responses were along the lines of "You have to use a where clause or turn off safe mode". But as you can see, I am using a where clause. Why is the error appearing if I have a where clause?

MySQL server version 5.6.20.

This image shows that rep_num is definitely my primary key:

This image shows the current rep table:

like image 348
Pikamander2 Avatar asked May 24 '26 04:05

Pikamander2


1 Answers

Although you save only numbers, your primary-key type is char(2) and not tinyint(2) and when you update the record you are giving numerical value instead char value in your where condition. I think thats where the indexing mechanism triggers the error and tells you, your where condition is unsafe or might yield wrong results.

in your case try

update rep 
set last_name = "Perry"
where rep_num = '85';

PS: why don't you name your tables with a prefix? like tbl_rep? just a thought.

like image 112
Krish Avatar answered May 25 '26 17:05

Krish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!