No error is reported when deleting data that does not exist in the table in MySQL

No error is reported when deleting data that does not exist in the table in MySQL

As long as there is an error in the sql statement in MySQL, there will be no error message under normal circumstances. So, there will be no error when using the following sql to delete

Sql statement:

delete from user where uname = '马保国';

Run result:
Affected rows: 0
Time: 0.014s

Among them, there is no teacher Ma in the user name, but the execution of the above code will not report an error, but he will display the execution result or affect the result to 0.

He just reminds you of the number of rows affected, and will not tell you whether the execution is successful or not. SQL is a declarative programming method. Unless it is a syntax error, insufficient permissions, or locks at the database level that cannot be executed, it will not be considered. Is wrong.

Solution:

When executing delete and update statements, first use the select method to determine whether there is data to be operated on in the table, so as to avoid direct execution and find the error. Modifying the code without error message is also a technical task.

Guess you like

Origin blog.csdn.net/m0_46202060/article/details/111312707