When working with SQL databases, a small mistake in an UPDATE statement can change hundreds or even thousands of records.
One common mistake is forgetting the "WHERE" clause.
Let's understand what happens with a simple example using Oracle SQL.
Consider a Customer Table
Imagine you are working on a customer database.
You have the following records:
CUSTOMERS
CUSTOMER_ID| CUSTOMER_NAME| STATUS
101| Amit| INACTIVE
102| Priya| ACTIVE
103| Rahul| INACTIVE
104| Sneha| ACTIVE
Your manager gives you a simple task:
Find customer 101.
Change the customer's status from "INACTIVE" to "ACTIVE".
Do not change any other customer records.
The UPDATE Query With a Mistake
A developer writes the following SQL statement:
UPDATE customers
SET status = 'ACTIVE';
At first glance, the query looks correct.
It uses the UPDATE statement and assigns a new value to the status column.
But there is an important problem.
The WHERE clause is missing.
What happens when you execute this query?
A.…