Lessons › SQL › Deep Dive: Database Admin & ETL
SQL lesson
SCD Type 1: overwriting a change
SCD Type 1 simply overwrites a customer's old value with the new one. Only today's value is kept.
Try this lesson free →Example
When the old value doesn't matter: overwrite it
UPDATE customers SET email = 'ada.obi@mail.com' WHERE customer_id = 'C101';
SELECT * FROM customers| customer_id | full_name | region | |
|---|---|---|---|
| C102 | Ben Cole | West | ben@mail.com |
| C103 | Cara Diaz | East | cara@mail.com |
| C101 | Ada Obi | East | ada.obi@mail.com |
Step by step
- SET gives the new value. The old one is overwritten, gone for good.
UPDATE customers SET email = 'ada.obi@mail.com' - WHERE makes sure only Ada changes. Without it, every customer would get this email.
UPDATE customers SET email = 'ada.obi@mail.com' WHERE customer_id = 'C101'; - One row per customer, with today's value.
UPDATE customers SET email = 'ada.obi@mail.com' WHERE customer_id = 'C101'; SELECT * FROM customers;
Practice
1. Type 1: change C102's email to 'ben.cole@mail.com', then show all customers.
UPDATE customers SET email = 'ben.cole@mail.com' WHERE customer_id = 'C102'; SELECT * FROM customers2. Type 1: change C103's region to 'North', then show all customers.
UPDATE customers SET region = 'North' WHERE customer_id = 'C103'; SELECT * FROM customers3. Type 1: correct C101's full_name to 'Ada Obi-Okafor', then show customer_id and full_name.
UPDATE customers SET full_name = 'Ada Obi-Okafor' WHERE customer_id = 'C101'; SELECT customer_id, full_name FROM customers4. Type 1: change C102's region to 'North' and email to 'ben@north.com' in one UPDATE, then show all customers.
UPDATE customers SET region = 'North', email = 'ben@north.com' WHERE customer_id = 'C102'; SELECT * FROM customers5. Type 1: every customer in 'East' is now in 'Eastern'. Update them, then show customer_id and region.
UPDATE customers SET region = 'Eastern' WHERE region = 'East'; SELECT customer_id, region FROM customersLearn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.
Try this lesson free →