The results returned by insert in mysql are: 1. If the insertion is successful, a message "Query OK, 1 row affected" indicating the success of the insertion operation will be returned; 2. If the insertion fails, an error message will be returned, which includes the reason for the failure. Detailed information; 3. Return a message "Query OK, 0 rows affected" indicating that the insertion operation was not executed, which means that although the insertion operation was not executed, no error occurred.
Operating system for this tutorial: Windows 10 system, MySQL 8 version, Dell G3 computer.
In MySQL, when executing the INSERT statement, the returned results can have the following situations:
If the insertion is successful, a message indicating that the insertion operation is successful is returned. Usually "Query OK, 1 row affected". This means that the database successfully inserted a row of data without errors.
If the insert fails, an error message is returned with details about the reason for the failure. For example, there may be duplicate key constraints, empty non-null fields, etc. that cause insertion failure.
If you use the INSERT IGNORE syntax and the inserted row has a unique key conflict, no error message will be returned, but a message indicating that the insert operation was not performed, usually "Query OK, 0 rows affected". This means that although the insert operation was not executed, no error occurred.
It should be noted that in MySQL, by default, executing an INSERT statement does not return the inserted specific record or primary key value. If you need to obtain the automatically generated primary key value after insertion, you can use related functions and syntax, such as the LAST_INSERT_ID() function or RETURNING clause (limited to certain MySQL versions).
In short, the INSERT statement in MySQL will return a corresponding message after executing the insertion operation, indicating the execution status of the insertion operation, including success or failure and possible error information.
The above is the detailed content of What does insert return in mysql?. For more information, please follow other related articles on the PHP Chinese website!