In our project, we are trying to combine multiple tables into a single table. The table has ukey and effective_date are PKs with not null constraint.
The structure works for below data as effective dates are different:
Ukey effective date combination:
| ukey | effective_date | settle_date | price |
|---|---|---|---|
| u123 | 3/3/2025 | 3/8/2025 | 1.21215 |
| u123 | 3/4/2025 | 3/9/2025 | 1.23 |
The requirement is for same ukey and effective_dates, there can be multiple settle_dates. So if I wanted to make it work for same ukey and effective_date, I will have to add settle_date as PK and make it non null. However there can be certain records where settle_date is null so adding settle_date with the data shown below won't work:
Ukey effective date settle_date combination:
| ukey | effective_date | settle_date | price |
|---|---|---|---|
| u123 | 3/3/2025 | 3/8/2025 | 1.21215 |
| u123 | 3/3/2025 | 3/9/2025 | 1.23 |
| u456 | 3/3/2025 |
Two solutions I have thought are:
- Always populate dummy value in
settle_dateeg 12/31/2999 makingsettle_dateas PK and non null. And wherever its applicable during data load, my table will have actualsettle_date. - Use sequence as
GENERATED BY DEFAULT AS IDENTITYand use it as PK rather thansettle_date. However there would be lot of INSERTS if I don't handle updates properly in the code.
Any other solution to this issue?
ukeyandeffective_date, if they all have nosettle_date? If so, are there any other features that distinguish them?