Check Constraints
Posted in 1995
Question. I have a table which preserves history. An active record has a NULL end_date. A historical record has a value in end_date for the time when it became obsolete. So the following is possible: filename end_date xyz 1/1/95 xyz 2/1/95 xyz 2/15/95 xyz 2/15/95 xyz 2/15/95 xyz NULL I wish to enforce, through constraints, that only one filename can be active (have a NULL end_date) at a given time. Just writing this I can see that changing end_date to a DATETIME and then adding a constraint of UNIQUE (filename, end_date) would have this effect. Does anyone have any other (better) ideas? By the same token I have another table with a similar problem. colnumber file_id end_date 1 1 1/1/95 2 1 1/1/95 1 5 2/1/95 2 5 2/1/95 1 5 2/1/95 2 5 2/1/95 1 5 2/1/95 2 5 2/1/95 1 5 2/1/95 2 5 2/1/95 1 10 NULL <--- valid 2 10 NULL <--- valid 1 11 NULL <--- valid 2 11 NULL <--- valid Again I can change to a datetime, any other ideas? adv(thanks)ance j. _____________________________________________________________________________ Jack Parker - Hewlett Packard, BSMC Boise, Idaho, USA jparker@hpbs3645.boi.hp.com _____________________________________________________________________________ "A thing is bigger for being shared" - Gaelic _____________________________________________________________________________ Any opinions expressed herein are my own and not those of my employers. _____________________________________________________________________________