Let us see how we can update data in the table.
Typical syntax
If WHERE
condition is not specified all rows in the table will be updated.
For now we will see basic examples for update. One need to have good knowledge about WHERE
clause to take care of complex conditions. Using WHERE
will be covered extensively as part of filtering the data at a later point in time.
Set user role for user_id 1 as ‘A’
user_id | user_first_name | user_last_name | user_email_id | user_email_validated | user_password | user_role | is_active | create_ts | last_updated_ts |
---|---|---|---|---|---|---|---|---|---|
1 | Scott | Tiger | scott@tiger.com | False | None | U | False | 2020-11-14 15:35:11.813351 | 2020-11-14 15:35:11.813351 |
2 | Donald | Duck | donald@duck.com | False | None | U | False | 2020-11-14 15:35:14.495991 | 2020-11-14 15:35:14.495991 |
3 | Mickey | Mouse | mickey@mouse.com | False | None | U | True | 2020-11-14 15:35:15.881686 | 2020-11-14 15:35:15.881686 |
4 | Gordan | Bradock | gbradock0@barnesandnoble.com | False | h9LAz7p7ub | U | True | 2020-11-14 15:35:20.938583 | 2020-11-14 15:35:20.938583 |
5 | Tobe | Lyness | tlyness1@paginegialle.it | False | oEofndp | U | True | 2020-11-14 15:35:20.938583 | 2020-11-14 15:35:20.938583 |
6 | Addie | Mesias | amesias2@twitpic.com | False | ih7Y69u56 | U | True | 2020-11-14 15:35:20.938583 | 2020-11-14 15:35:20.938583 |
user_id | user_first_name | user_last_name | user_email_id | user_email_validated | user_password | user_role | is_active | create_ts | last_updated_ts |
---|---|---|---|---|---|---|---|---|---|
2 | Donald | Duck | donald@duck.com | False | None | U | False | 2020-11-14 15:35:14.495991 | 2020-11-14 15:35:14.495991 |
3 | Mickey | Mouse | mickey@mouse.com | False | None | U | True | 2020-11-14 15:35:15.881686 | 2020-11-14 15:35:15.881686 |
4 | Gordan | Bradock | gbradock0@barnesandnoble.com | False | h9LAz7p7ub | U | True | 2020-11-14 15:35:20.938583 | 2020-11-14 15:35:20.938583 |
5 | Tobe | Lyness | tlyness1@paginegialle.it | False | oEofndp | U | True | 2020-11-14 15:35:20.938583 | 2020-11-14 15:35:20.938583 |
6 | Addie | Mesias | amesias2@twitpic.com | False | ih7Y69u56 | U | True | 2020-11-14 15:35:20.938583 | 2020-11-14 15:35:20.938583 |
1 | Scott | Tiger | scott@tiger.com | False | None | A | False | 2020-11-14 15:35:11.813351 | 2020-11-14 15:35:11.813351 |
Set user_email_validated as well as is_active to true for all users
Convert case of user_email_id to upper for all the records
Add new column by name user_full_name and update it by concatenating user_first_name and user_last_name.
user_id | user_first_name | user_last_name | user_full_name |
---|---|---|---|
2 | Donald | Duck | DONALD DUCK |
3 | Mickey | Mouse | MICKEY MOUSE |
4 | Gordan | Bradock | GORDAN BRADOCK |
5 | Tobe | Lyness | TOBE LYNESS |
6 | Addie | Mesias | ADDIE MESIAS |
1 | Scott | Tiger | SCOTT TIGER |