Explain how to implement Change Data Capture type 2 using effective start time, end time, and current flag fields. The current flag indicates whether a record is active; the start time indicates when it became active, and the end time indicates when it became inactive. These fields are required. How would you implement this in software?
1Times asked
Jul 2026Last seen
Jul 2026First seen
💡 Model Answer
Change Data Capture (CDC) type 2 preserves historical versions of a record by adding three columns: start_date, end_date, and current_flag. The implementation steps are:
- Detect change: Compare incoming source rows with the latest row in the target where current_flag = 1.
- If unchanged: Do nothing.
- If changed:
- Update the existing row: set end_date to the change timestamp and current_flag to 0.
- Insert a new row with the new values, start_date set to the change timestamp, end_date set to a sentinel value (e.g., 9999‑12‑31), and current_flag = 1.
- Batching: Process changes in batches to reduce lock contention. Use a staging table to hold incoming changes, then run a MERGE statement that performs the update/insert logic.
- Indexing: Index on the natural key and current_flag to speed up lookups.
Complexity is O(n) per batch, where n is the number of changed rows. This approach guarantees that every historical state is retained and that queries can filter on current_flag = 1 for the latest view or on a date range for historical analysis.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.
Get Assisting AI — Starts at ₹500