w3resource

PostgreSQL Update Table: Change the value of a column with user defined text


1. Write a SQL statement to change the email column of the employees table with 'not available' for all employees.

Sample table: employees


Sample Solution:

Code:

-- This SQL statement updates the 'email' column in the 'employees' table, setting all values to 'not available'.

UPDATE employees SET email='not available';

Explanation:

  • The UPDATE statement is used to modify existing records in a table.
  • employees is the name of the table being updated.
  • SET email='not available' specifies that the value of the 'email' column for all rows should be set to 'not available'. This effectively replaces the existing email addresses with the string 'not available' for all employees in the table.

Output:

See the result. Only two rows have been displayed.

postgres=# SELECT * FROM employees LIMIT 2;
 employee_id | first_name | last_name |     email     | phone_number | hire_date  | job_id  |  salary  | commission_pct | manager_id | department_id
-------------+------------+-----------+---------------+--------------+------------+---------+----------+----------------+------------+---------------
         100 | Steven     | King      | not available | 515.123.4567 | 1987-06-17 | AD_PRES | 24000.00 |           0.00 |          0 |            90
         101 | Neena      | Kochhar   | not available | 515.123.4568 | 1987-06-18 | AD_VP   | 17000.00 |           0.00 |        100 |            90

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: PostgreSQL Update Table - Exercises, Practice, Solution
Next: Write a SQL statement to change the email and commission_pct column of the employees table with 'not available' and 0.10 for all employees.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/postgresql-exercises/update-table/update-table-exercise-1.php