The safe UPDATE mode in MySQL
To understand safe UPDATE mode, we will consider a table, students_data, and display it using the command:
If we try to make changes either by updating the data or deleting the data it will generate an error because by default the safe UPDATE mode is always enabled, to check it we will make update the value of “Paul” to “Tom” using the command:
It can be seen from the output that an error has been generated of the safe update mode, which means safe mode has been enabled and it will not allow us to make any changes in the table; to make changes we have to first, disable the safe update mode.
How to disable the safe UPDATE mode in MySQL
We can disable the safe UPDATE mode in MySQL, if we want to make some changes in the tables, to do so run the following command:
<img class="wp-image-137634" src="https://linuxhint.com/wp-content/uploads/2021/11/word-image-762.png" />
After disabling the safe UPDATE mode, again run the previous command to change the name of “Paul” to “Tom” using the command:
[cc lang="mysql" width="100%" height="100%" escaped="true" theme="blackboard" nowrap="0"]
UPDATE students_data SET St_Name='Tom' WHERE St_Name='Paul';
The table has been updated successfully, to display the table:
How to enable the safe Update mode in MySQL
In order to again enable the safe Update mode in MySQL, execute the following command:
To verify that the safe UPDATE mode has been enabled, we will change the “Houston” city to “Paris”, using the command:
The safe UPDATE mode has been successfully enabled.
MySQL is a well-known database management system that offers many features to its users which help them to enhance the performance of their tasks. In this write-up, we have discussed the safe UPDATE mode in MySQL through which we can restrict the users to update the tables by enabling or disabling the safe UPDATE mode. In this guide, we discussed both scenarios of enabling and disabling the safe UPDATE mode and checked its impact on the update command.