database - Inheritance and model Id -
i have person class in contacts subsystem. on other hand in crm subsystem, have notion of customer.
in database design, want create relationship between these notions. there possible ways:
- each customer is person, customer should inherit person , customer dies person removed (composition). in case, create
one-to-onerelationship betweenidcolumns ofcustomerstable ,peopletable, , makeidcolumn ofpeopletable identity field, explicitly insertscope_identity()incustomerstable. - each customer has person, customer , person have own life-cycles (aggregation) , can survive without other. in scenario,
customerstable should have foreign keypeopletable. bad point here eachpersoncan have manycustomersseems odd me.
which design suggested best practice? need solid objective answers. thank you.
there different cases when may or may not give each table it's own id.
in case, better if customer table have it's own id.
example: own id in many many relation defining table redundant, when doesn't have column associated apart tables joining. consider teacher , student table relation. have many many relation. if there table named teacherstudentrelation having foreign key teacher , student table won't need ownid field.
but in case, customer table surely have information associated balance, purchaselist or that. , highly search customer table data. here ownid of customer table let index table.
briefly, give customer table it's own id.
Comments
Post a Comment