PL-SQL
Oracle PL/SQL: CASE Statement with Examples
What is CASE Statement? A CASE statement is similar to IF-THEN-ELSIF statement that selects one...
The basic syntax of the Update query in MySQL is as shown below.
UPDATE `table_name` SET `column_name` = `new_value' [WHERE condition];
HERE
Let's now look at a practical example that updates data in the members table. Let's suppose that our member's membership numbers 1 and 2 have the following updates to be made to their data records.
| Membership number | Updates required |
| 1 | Changed contact number from 999 to 0759 253 532 |
| 2 | Change the name to Janet Smith Jones and physical address should be updated to Melrose 123 |
We will start with making updates for membership number 1 before we make any updates to our data, let's retrieve the record for membership number 1. The script shown below helps us to do that.
SELECT * FROM `members` WHERE `membership_number` = 1;
Executing the above script gives us the following results.
membership_number full_names gender date_of_birth physical_address postal_address contct_number 1 Janet Jones Female 21-07-1980 First Street Plot No 4 Private Bag 999 This email address is being protected from spambots. You need JavaScript enabled to view it.
Let's now update the contact number using the script shown below.
UPDATE `members` SET `contact_number` = '0759 253 542' WHERE `membership_number` = 1;
Executing the above script updates the contact number from 999 to 0759 253 532 for membership number 1. Let's now look at the record for membership number 1 after executing the update script.
SELECT * FROM `members` WHERE `membership_number` = 1;
Executing the above script gives us the following results.
membership_number full_names gender date_of_birth physical_address postal_address contct_number 1 Janet Jones Female 21-07-1980 First Street Plot No 4 Private Bag 0759 253 542 This email address is being protected from spambots. You need JavaScript enabled to view it.
Let's now look at the updates required for membership number 2.
| membership_number | full_names | gender | date_of_birth | physical_address | postal_address | contct_number | |
|---|---|---|---|---|---|---|---|
| 2 | Smith Jones | Female | 23-06-1980 | Park Street | NULL | NULL | This email address is being protected from spambots. You need JavaScript enabled to view it. |
The following script helps us to do that.
UPDATE `members` SET `full_names` = 'Janet Smith Jones', `physical_address` = 'Melrose 123' WHERE `membership_number` = 2;
Executing the above script in updates the full names for membership number 2 to Janet Smith Jones and the physical address to Melrose 123.
membership_number full_names gender date_of_birth physical_address postal_address contct_number 2 Janet Smith Jones Female 23-06-1980 Melrose 123 NULL NULL This email address is being protected from spambots. You need JavaScript enabled to view it.
What is CASE Statement? A CASE statement is similar to IF-THEN-ELSIF statement that selects one...
What are functions? MySQL can do much more than just store and retrieve data . We can also perform...
SQL Tutorial Summary Databases can be found in almost all software applications. SQL is the...
$20.20 $9.99 for today 4.6 (119 ratings) Key Highlights of SQLite PDF 159+ pages eBook Designed for...
What is PL/SQL block? In PL/SQL, the code is not executed in single line format, but it is always...
What is Normalization? Normalization is a database design technique that reduces data redundancy and...