sql server 2008 - SQL table design with contigent constraints -
i have table design problem need cunning solution.
let's have 2 tables, relationship:
contract 1---n payment
now, let's have legacy data needs go these tables. problem though many of legacy payment entries aggregated across mulitple contracts
so view as:
new:
somethingabovecontract 1---n contract 1---n payment
legacy:
somethingabovecontract 1---n payment
now, can around creating m-n relationship between contract , payment.
contract 1---n contractpayment n---1 payment
(it possible me identify contracts linked aggregated payment)
this fine legacy data, want enforce 1-n relationship between contract , payment going forward. so, using unhandy scribble illustrate, this:
i.e. payment aggregate, contractid null, otherwise should not null. in other words, need find way enforce following contingencies on payment table:
- contractid nullable if paymentid appears in contractpayment
- contractid not nullable if paymentid not appear in contractpayment
i don't know how though.
even if possible, seem bit ugly (which legacy data conversion invariably is). if has more elegant solution great. otherwise, works!
thanks
karl
use 2 (sets of) tables, 1 'legacy' , 1 going forward. should able define business rules , without need nullable columns (sql's 3 value logic disaster). privileges revoked on 'legacy' table(s) ensure not used going forward.
Comments
Post a Comment