Subject | Re: [firebird-support] Help a geezer? |
---|---|
Author | Florian Hector |
Post date | 2006-09-18T05:08:01Z |
>What about some normalization?
> Unit: the floor where procedure was performed
> Procedure: What procedure was performed
> Date: When the therapist did it.
> Shift: Day,Evening, or Night.
> Scheduled: Did you know about it ahead of time or was it a STAT
> Total: How many of these suckers did you do
>
> As I see it, each record is unique. So I'm struggling with a logical
> schema.
> Pseudocode follows:
>
> CREATE TABLE unit_record (
> unit Varchar (15) // the floor
> uprod Varchar (15) // the procedure
> total Varchar (4) // how many
> udate Date // When was it done (time is not an issue, shift is)
> ushift Varchar (1) // what shift
> usched Varchar (1) // STAT or not?
> );
>
CREATE TABLE FLOORS (
ID INTEGER,
FLOORNAME VARCHAR(15),
FLOORREM VARCHAR(200));
ALTER TABLE FLOORS ADD CONSTRAINT PK_FLOORS PRIMARY KEY (ID);
CREATE TABLE UPROD (
ID INTEGER NOT NULL,
PRODNAME VARCHAR(15),
PRODREM VARCHAR(200);
ALTER TABLE UPROD ADD CONSTRAINT PK_UPROD PRIMARY KEY (ID);
More tables.....
After you have defined all the detail tables you create the table that holds the actual information
CREATE TABLE UNIT_RECORD (
ID INTEGER NOT NULL,
FLOORID INTEGER,
UPRODID INTEGER
More references to other tables...
);
ALTER TABLE UNIT_RECORD ADD CONSTRAINT PK_UNIT_RECORD PRIMARY KEY (ID);
ALTER TABLE UNIT_RECORD ADD CONSTRAINT FK_FLOORS FOREIGN KEY (FLOORID) REFERENCES FLOORS (ID);
ALTER TABLE UNIT_RECORD ADD CONSTRAINT FK_UPROD FOREIGN KEY (UPRODID) REFERENCES UPROD (ID);
More foreign key constraints ....
Florian