How can I deal with this problem of designing generalizations?

Our database model has a Recipient object . The beneficiary can be an individual or a corporate recipient; the physical beneficiary has a number of attributes, such as first name, last name, gender, etc .; in addition, the beneficiary (corporate or individual) may be either foreign or not; this further difference translates into different domain values ​​for a “common” set of attributes (for example, in Italy, where I live, tax IDs may have a different data format than UK tax IDs).

Now we are processing our Beneficiary table, since the developer who initially worked on the analysis and modeling of the database made an (IMO) short-sighted choice. He put a primary key restriction on the BeneficiaryName attribute, which was used to store either a corporate name (for example, "Microsoft Corporation") in the case of a corporate beneficiary, or a surname (for example, Smith) for the physical beneficiary. Thus, we have a (unacceptable) restriction that we CANNOT have more than 1 beneficiary with the name "Smith" (or a corporation with the name "Smith") in our database.

My approach to this “re-factoring" will lead to a generalization for the beneficiary subject; I'd

  • Clear the Recipient table, saving only general data;
  • Add a surrogate primary key to the recipient table, call BeneficiaryID;
  • Split the recipient table by creating two subsystems ( CorporateBeneficiary and physically beneficial , discriminated by the flag in the recipient's main table), from 1..1 to the recipient table (the foreign key will refer to the Beneficiary).
  • Find (meaningful) primary keys for CorporateBeneficiary and PhysicalBeneficiary ;

This should address the aforementioned uniqueness problem in the BeneficiaryName name. Seems so far?

, , - : , "foreign" ?. Foreign tis, .. ? , (, zipcode, tax id) (zipcode_foreign, zipcode, taxid_foreign, taxid ..)? ?

...

+3
4

" , ;"

, .

" , BeneficiaryID;"

, , "" , .

"- , (CorporateBeneficiary PhysicalBeneficiary)

. , "" ( , , ), , ).

", "

. . , . , , , .

" () CorporateBeneficiary PhysicalBeneficiary;

Benficiaries , . , .

" , , : / , " foreign " ?" "

, National ExtraNational ( , ), , , , , Benficiaries. , , , SSN "" . , , , , . , .

, , , , "" ( ) , "" "" "" , , , CHAR ( , , , , SSN, ).

National Non-National , "" "" , , .

+5

, , - - . :

CorporateBeneficiary/PhysicalBeneficiary :

  • , (BeneficiaryID).
  • BeneficiaryID , .
  • CorporateBeneficiary (CB) PhysicalBenificiary (PB) - .. BeneficiaryID.
  • CB PB , Beneficiary.

:

  • , .
  • CB/PB - .. .

, , " " - /PB/ . .

( > 10 ^ 7 ), , . ; ; , .

, , @James Anderson, ( ) .

+2

.

, , . ( , !). i18n , , Line2, Line3, Line4 .

, , 4 /[A-Z0-9] {2,4} [A-Z0-9] { 2,4}/ ( ", , , " ). , ( , CH .. ..), , , , .

+1

, :

( 1 , 2 )


1.

.

:

  • JOINs, UNION (= )

:

  • many NULL
  • ,
  • ( , ).

PKs/FKs: , FKs

: "".


2.

. .

:

:

  • (UNION = slow)
  • ( )

PKs/FKs: PK, FK

: "CorporateBeneficiary" "PhysicalBeneficiary"


3.

. ( , .)

:

:

  • (JOIN = slow)

PKS/FKS: PK, . (.. Oracle). pk- fk- . , - Oracle Sequences. pk fk PK . (.. gen )


, . 1.) 3.), , 2.) , .

Personally, when I have no other boundary conditions, I choose 3 because I consider this the cleanest solution. But I also chose option 1 in the past due to performance. I don’t remember that from the university I did something like option 2 .: P

0
source

All Articles