3

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:

Pikamander2
  • 7,332
  • 3
  • 48
  • 69

1 Answers1

1

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.

Krish
  • 5,917
  • 2
  • 14
  • 35