Re: Help finding natural keys
Date: 17 Jan 2003 10:39:18 -0800
Message-ID: <c0d87ec0.0301171039.58bf8fca_at_posting.google.com>
>> I am generating keys using select max. I've considered what Mr
Celko says about how this is just a sequential file model in SQL, but
I try as I might,
I can't think of good, er, natural keys for my entities. <<
>> Have I just fallen into a bad habit? Are there candidate keys for
things
like a person that I just cannot see? <<
>> CREATE TABLE Firms
(firm_id INTEGER NOT NULL PRIMARY KEY,
firm_name VARCHAR(32) NOT NULL);
The firm may change it's name, so that doesn't make for a good key. <<
>> CREATE TABLE Patients
(firm_id INTEGER NOT NULL
REFERENCES Firms(firm_id),
A patient is a charge of a particular hospital so, I select the max
patient
patient_id INTEGER NOT NULL
PRIMARY KEY (firm_id, patient_id));
id for the hospital to get a new patient id. <<
>> CREATE TABLE Questionnaires
(firm_id INTEGER NOT NULL
REFERENCES Firms(firm_id),
questionnaire_id INTEGER NOT NULL
PRIMARY KEY (firm_id, questionnaire_id));
... There is no unique identifier for these things in the real world
where
they are photocopied Word documents designed by a nurse. <<
Nobody can help you if the reality you are trying to model is screwed up.
>>
CREATE TABLE Completed_Questionnaires
(firm_id INTEGER NOT NULL
REFERENCES Firms(firm_id),
questionnaire_id INTEGER NOT NULL,
completed_questionnaire_id INTEGER NOT NULL,
PRIMARY KEY (firm_id, questionnaire_id, completed_questionnaire_id));
Here is an instance of a questionnaire. A questionnaire might be
completed a
number of times during a patient's care, like a progress report form.
Again, select MAX(). <<
Completion is an attribute of a questionnaire. This sounds more like an occurence of a questionnaire which has a date or serial number assoicated with it. Received on Fri Jan 17 2003 - 19:39:18 CET
