Translate

Monday, 24 April 2017

MySQL : While delete record from table where clause doesn't contain primary key column ie AnyColumn

If I delete record from a table with where condition and in where clause the column is primary key then there is no error
ie
delete from  mydatabasename.tableName
where Id=33;commit;
 here there is no error .

where as  While the below case
If I delete record from a table with where condition and in where clause the column is not a  primary key then there is  error
ie
below example

delete from  mydatabasename.tableName
where date_format(record_date,'%Y/%m/%d')='2017/04/24';commit;

Error:
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 Editor and reconnect.

Solution:

set sql_safe_updates = 0;
delete from  mydatabasename.tableName
where date_format(record_date,'%Y/%m/%d')='2017/04/24';commit;
SET sql_safe_updates = 1;

No comments:

Post a Comment