Re: Schema Anomalies
- From: "DM Unseen" <dm.unseen@xxxxxxxxx>
- Date: 6 Sep 2005 01:34:25 -0700
I think The "implied relationships" is somehat trickier to check.
Take for example:
Customer:
CustomerID
Billing2AddressID
Shipping2AddressID
Address:
AddresID
City
Zip
etc....
Currently your setup only checks for Natural joins (where foreign key
column names equal the primary key column names). This is OK.
But this is only the simple version of implied relationships. In a
database where multplie roles are used this is never going to
happen(esp. when the naming convention takes this into consideration
for all foreign keys!). For good naming conventions however it is
imperative that the names of the primary key column names also show up
on the foreign key names, or that the entity of the primary key shows
up on the foreign key name. The last option is probably the rarest.
I know checking all options is going to be tricky!
I would say you would (Optionally) check if a column name starts or
ends with a column name of a primary key would be a good heuristic
choice. A good naming convention will stick to this approach in one way
or another. I think that is about the most you can do to find implied
relationships.
I know of databases that actually have no SQL relations defined "by
design", beacuse they would only mean extra overhead on the database
server. While the database will not enforce referential integrity this
way, you can still have a database without any referential anomaly.
The discussions on single culumn tables (AKA lookup tables) goes long
and wide. From the (fundamental) design side, the more tables the
better (since tables are linked to semantics of the model). From
programming side the less tables the better. The truth lies always
somewhere in between.
A good rule of the thumb I use is this:
If I lump 2 lookup tables together, and values get mixed up(used
illegally) inside the database, how bad is it?
catastrophic? These 2 lookup tables should be distinct
problematic? These 2 lookup tables should be distinct
nuisance? These 2 lookup tables could be joined into a larger table
Using this rule you usually end up with a load of small but important
lookup tables, and one big lookup table with all the rest of the
lookups.
Another way to look at it is the following:
Is the contents of the lookup table owned/used by the
system/application/program in a very specific way, then it needs it's
own table.
Is the contents of the lookup table owned/changable by the user and of
no consequence to the system, you can stick it in one big lookup table.
there are globally 2 ways to look at relations:
symmetric:
Table1:
OTM (Mandatory) Table2
(Optional) OTOP Table3
Table2:
(Mandatory) MTO Table1
Table3:
OTOF (Optional) Table1
Assymatric:
Relations:
Relation1: Table1 OTM (Mandatory) Table2
Rerlation2: Table1 (Optional) OTOP Table3
You can check One To One relationship based on unique index/contsraint
on foreign key. Also Mandatory = Foreign Key Not NULL, Optional =
Foreign Key NULL,
Mmm, the intersection/junction table terminology is more of a flavor,
but maybe junction table would be more accepted.
Note that a binary junction table = (binary)MTM relationship.
If it is not that difficult, maybe also recognize a primary key on an
intersection table? This is also a bad habit of some database designers
that could stand a check.
DM Unseen
.
- Follow-Ups:
- Re: Schema Anomalies
- From: John Currier
- Re: Schema Anomalies
- References:
- Schema Anomalies
- From: John Currier
- Re: Schema Anomalies
- From: DM Unseen
- Re: Schema Anomalies
- From: John Currier
- Schema Anomalies
- Prev by Date: attn: jenda - genuinely incredible active newsgroups - rucga ad - (1/1)
- Next by Date: mysql query help
- Previous by thread: Re: Schema Anomalies
- Next by thread: Re: Schema Anomalies
- Index(es):
Relevant Pages
|
|