mysql - Is it okay to reference the primary keys of all tables in database as a foreign key of one table? -
i trying make demo database have tables
household(primary key - hid) people(primary key - pepid) parchildold(primary key - pcoid) job(primary key - empid) school(primary key - schlid) pension(primary key - penid)
now have various attributes details of people in each household in different tables.
can take primary keys of tables , make 1 table, allkeys , reference them foreign keys in particular table?
ie:
allkeys table primary key: akid -- other columns include foreign keys- hid,pepid,pcoid,empid,schid,penid*
i don't know if silly ask or not, but,
is such reference allowed? can considered normalized form? queries fired in way joining allkeys table , other table(depending on query) work efficiently?
you if of tables related, fail third , fourth normal forms, having both functional , multivalued dependencies in table.
consider huge amounts of duplication required store relationships single household: 1 household (hid=1), 2 parents (pepid=1,2), 2 children (pepid=3,4), 4 parent-child relationships (pcoid=1,2,3,4), 2 jobs (empid=1,2), 1 school both children (schlid=1) , 2 pensions (penid=1,2).
akid | hid | pepid | pcoid | empid | schlid | penid -----|-----|-------|-------|-------|--------|------ 1 | 1 | 1 | 1 | 1 | null | 1 2 | 1 | 1 | 2 | 1 | null | 1 3 | 1 | 2 | 3 | 2 | null | 2 4 | 1 | 2 | 4 | 2 | null | 2 5 | 1 | 3 | 1 | null | 1 | null 6 | 1 | 3 | 2 | null | 1 | null 7 | 1 | 4 | 3 | null | 1 | null 8 | 1 | 4 | 4 | null | 1 | null
another problem that, assuming table parchildold contains parent , child column, have no way of specifying whether pcoid reference in allkeys, whether pepid refers parent or child.
in short, don't it.
Comments
Post a Comment