advancedTop 15 Database Design Questions

Design a database that handles slowly changing dimensions (SCD Type 2) for customer data.

customers_history(id BIGSERIAL, customer_id INT, name, email, address, valid_from DATE, valid_to DATE NULLABLE, is_current BOOLEAN) On update: UPDATE old row: valid_to = TODAY, is_current = FALSE; INSERT new row: valid_from = TODAY, valid_to = NULL, is_current = TRUE Partial index on current records: CREATE INDEX ON customers_history(customer_id) WHERE is_current = TRUE Query current: WHERE is_cur

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to Design a database for distributed message queue / event store.← Back to all SQL questions