Re: Database naming convention (yet another post of it, but a bit different)
Date: 9 Oct 2002 16:35:51 -0700
Message-ID: <c0d87ec0.0210091535.5ad009a6_at_posting.google.com>
>> I prefer the singular. :) Especially when it comes to cases where
Then use a singlular name and enforce this rule with a constraint:
we have a table with one row. <<
CREATE TABLE PhysicalConstants
(lock INTEGER NOT NULL PRIMARY KEY
DEFAULT 0 CHECK (lock = 0),
pi FLOAT NOT NULL,
e FLOAT NOT NULL,
...);
INSERT INTO PhysicalConstants
Unh? Tables usually start as a set, not as a singularity.
VALUES (1, 3.141592653, ...);
>> Because the business world is fickle, that one row table may become
a multiple row table in the future. <<
>> Additionally, when I validate the model, we talk about a single row
[master] ----> [detail]
(0,N) (1,1)
A [master] may or may not have a [detail]
A [detail] has at least one and at most one [master] <<
You do know you are using terms from IMS and not SQL, don't you? We
have referenced and referencing columns, not "master" and "details".
against the cardinality:
>> You could also consider dashes instead of underscore. <<
>> I don't get too worked up about case. <<
Human beings read lowercase MUCH more accurately than all uppercase. When we had Cobol and used punch cards, it was a real problem. This is why newspaper and book don't use all uppercase. There are a ton of studies from the 1970's about readabilty of code.
>> There's some value to having each table's primary key column name
have the table name in it. It makes natural joins easier, and is
useful for documentation purposes w/ foreign keys. <<
Only if it that name describes the attribute. Would you really write "Inventory_UPC" instead of just plain old, easy to understand "upc"? Again, ISO-11179 says name things for what they are, not for where they are currently located. Do you say "John_on_the_steps" and "John_in_the_hall" and so forth?
>> Using the above naming convention, where all tables get a surrogate
It is an improper abstraction, based on PHYSICALLY and not LOGICAL
rules. Primary keys do not change often or quickly -- see the move
from UPC to GTIN codes in retail. And I was right!! You used "child
and parent" right out of IMS and network databases!! When I taught
key (builds a proper abstraction between implementation and the
business side changing its definition of a primary key!) and the
children tables building the FK as: parent + "primary column name",
developers can _easily_ code up their SQL. <<
>> Additionally, if one is building triggers, it's very easy to write
Now your age is showing! EMACS is going to scare the kids reading
this <G> Why didn't you use DRI actions instead of triggers?
Triggers are not portable yet in spite of Standards. They are
non-relational kludges and usually slow as hell.
an EMACS keyboard macro to write the trigger code. I did this for a
client and built RI for 20 tables in 15 minutes. <<