PostgreSQL Database Quiz Questions

Course Name:PostgreSQL
Chapter Name:Chapter 6 - DML (Data Manipulation Language)
Lesson Content Link:UPDATE
Current Quiz Count:30
Progress
0%
Q1
True / False

The UPDATE statement in PostgreSQL can be used to change existing records in a table.

Q2
True / False

In PostgreSQL, the UPDATE statement must include the WHERE clause.

Q3
True / False

The SET keyword is used in PostgreSQL UPDATE statements to specify the columns and new values.

Q4
True / False

In PostgreSQL, you can use subqueries in the SET clause of an UPDATE statement.

Q5
True / False

PostgreSQL allows you to update multiple columns in a single UPDATE statement.

Q6
True / False

You cannot use the RETURNING clause in a PostgreSQL UPDATE statement to return the updated rows.

Q7
True / False

PostgreSQL supports the use of common table expressions (CTEs) with UPDATE statements.

Q8
True / False

In PostgreSQL, it is possible to perform an UPDATE on a table and use the FROM clause to join with other tables.

Q9
True / False

PostgreSQL automatically creates an index on columns that are frequently updated.

Q10
True / False

PostgreSQL’s UPDATE statement does not support the USING clause to join tables during the update operation.

Q11
Single Choice

What is the correct syntax to update a single column value in PostgreSQL?

SQL Code
UPDATE employees
SET salary = 50000
WHERE id = 1;
Q12
Single Choice

What will happen if you omit the WHERE clause in a PostgreSQL UPDATE statement?

Q13
Single Choice

Which keyword is used in a PostgreSQL UPDATE statement to change the value of a column?

Q14
Single Choice

How do you update multiple columns in a PostgreSQL table?

SQL Code
UPDATE employees
SET salary = 60000, position = 'Manager'
WHERE id = 2;
Q15
Single Choice

How can you update a column in PostgreSQL using data from another table?

SQL Code
UPDATE employees
SET salary = departments.avg_salary
FROM departments
WHERE employees.department_id = departments.id
AND departments.name = 'Sales';
Q16
Single Choice

What happens when you update a row that does not satisfy the WHERE condition in PostgreSQL?

Q17
Single Choice

How do you use a subquery in the SET clause of a PostgreSQL UPDATE statement?

SQL Code
UPDATE employees
SET salary = (SELECT MAX(salary) FROM employees WHERE department_id = 2)
WHERE department_id = 2;
Q18
Single Choice

How can you safely update rows in PostgreSQL with a condition that includes NULL values?

SQL Code
UPDATE employees
SET salary = 45000
WHERE department_id IS NULL;
Q19
Single Choice

How do you conditionally update rows in PostgreSQL based on a complex condition?

SQL Code
UPDATE employees
SET bonus = CASE
 WHEN performance = 'Excellent' THEN 1000
 WHEN performance = 'Good' THEN 500
 ELSE 0
END
WHERE department_id = 3;
Q20
Single Choice

How can you update rows in PostgreSQL and return the updated rows as a result?

SQL Code
UPDATE employees
SET salary = salary * 1.10
WHERE department_id = 4
RETURNING *;
Q21
Multiple Choice

Which SQL command updates a single column in a PostgreSQL table?

SQL Code
UPDATE employees
SET salary = 60000
WHERE employee_id = 1;
Q22
Multiple Choice

Which SQL command updates multiple columns in a PostgreSQL table?

SQL Code
UPDATE products
SET price = 19.99, stock = stock - 1
WHERE product_id = 101;
Q23
Multiple Choice

Which SQL command uses a subquery to update a PostgreSQL table?

SQL Code
UPDATE employees
SET department_id = (
 SELECT department_id FROM departments WHERE department_name = 'HR'
)
WHERE employee_id = 1;
Q24
Multiple Choice

Which SQL command updates a table in PostgreSQL using data from another table?

SQL Code
UPDATE sales
SET total_amount = orders.total_amount
FROM orders
WHERE sales.order_id = orders.order_id;
Q25
Multiple Choice

Which SQL command updates a column conditionally using a CASE statement in PostgreSQL?

SQL Code
UPDATE employees
SET bonus = CASE
 WHEN department_id = 1 THEN 500
 WHEN department_id = 2 THEN 300
 ELSE 100
END;
Q26
Multiple Choice

Which SQL command updates a column by incrementing its value in PostgreSQL?

SQL Code
UPDATE inventory
SET stock = stock + 10
WHERE product_id = 202;
Q27
Multiple Choice

Which SQL command updates a table in PostgreSQL by setting a column to a NULL value?

SQL Code
UPDATE orders
SET shipping_date = NULL
WHERE order_id = 305;
Q28
Multiple Choice

Which SQL command updates a table in PostgreSQL using a JOIN clause?

SQL Code
UPDATE employees e
SET e.salary = s.new_salary
FROM salary_updates s
WHERE e.employee_id = s.employee_id;
Q29
Multiple Choice

Which SQL command updates a table and logs the old values using the RETURNING clause in PostgreSQL?

SQL Code
UPDATE employees
SET salary = salary * 1.05
WHERE department_id = 3
RETURNING employee_id, old_salary = salary / 1.05;
Q30
Multiple Choice

Which SQL command uses an UPDATE statement to set a column value conditionally and ensure no conflict occurs in PostgreSQL?

SQL Code
UPDATE customers
SET email = 'new_email@example.com'
WHERE NOT EXISTS (
 SELECT 1 FROM customers WHERE email = 'new_email@example.com'
) AND customer_id = 42;