Updating a specific row in sql
Please note that it will be very hard to practice these statements unless we switch off the following feature of Workbench.
We can expand the Edit tab from the Main Menu and opt for “Preferences”.
Of course, we can still say we have updated the specific record! After that, we will select the same employee through the employee number once again. Please note the following feature of the UPDATE statement.
Had we used a non-existent condition in the WHERE clause (for instance, an employee number of 999909), My SQL would have allowed the execution of the query, given that the SQL syntax is correct.
Right before that, we will execute a COMMIT command. Now, if we write the code that updates the “Department Duplicate” table, setting a department number equal to D-0-1-1 and a department name “Quality Control”, and then run it, we will modify all rows of the data table. This would typically happen by mistake – when the WHERE clause and the accompanying conditions have not been added. When executed, it will take us to the last COMMIT that has been run.One can always make a simple mistake that could result in the loss of a large amount of data. One last thing – to properly switch off the safe updates, reconnection to the database is required. It is used to update the values of existing records in a table.So, let’s exit this connection and then reconnect, typing the password once again! In the previous post about SQL INSERT Statement, we inserted an employee under the number of 9-9-9-9-0-1, remember? The syntax to adhere to is UPDATE table name, the keyword SET, column names and the respective values assigned to them, and finally – WHERE, and a certain condition, or set of conditions, that must be satisfied.Nevertheless, nothing would have happened – the statement would have worked, affecting 0 rows, because the data table doesn’t contain an employee with such a number at the moment of the query’s execution.Stay focused for another interesting feature we will discuss next.