+ 1

Please tell me why error is coming in my sql code

create table stu (id int primary key, name varchar(50), age int not null, subject varchar(50)); insert into stu values(1, "Meenakshi", 45, "Biology"); insert into stu values(2, "Roma", 32, "English"); insert into stu values(3, "Katherine", 26, "GK"); insert into stu values(5, "Shravya", 39, "Maths"); insert into stu values(6, "Jyoti", 41, "Geography"); insert into stu values(7, "Jyoti", 51, "History"); delete from stu where age=51; select * from stu I am getting this error-- 0 27 23:46:19 delete from stu where age=51 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. 0.000 sec Please help me rectify the error.

18th May 2024, 6:18 PM
Mallika Gupta
2 Respostas
0
as I see: in sql you need ";" at the end of the statements;
18th May 2024, 6:29 PM
Mihaly Nyilas
Mihaly Nyilas - avatar
0
I don't think the code has error, only the engine setting prevent the code to run. As the Error Code says: 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... Imagine you have the 8 entry like this: insert into stu values(8, "Wong", 51, "Japanese"); If you run "delete from stu where age=51", which record should be deleted? 7, 8, or both? The proper way would be: delete from stu where id=7; Using the KEY (id) as suggested. If you turn-off safe mode as the error code suggested and run your original code with the 8 entry, both id 7 & 8 will get deleted, and this may not be the result you wanted.
19th May 2024, 2:04 AM
Wong Hei Ming
Wong Hei Ming - avatar