3nf.pharma

Upload: mayank-gupta

Post on 06-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 3nf.pharma

    1/4

    First Normal Form

    If a relation contains no repeating groups, then it is in first normal form. Conversely, if we find that for a single primary key, we have

    two data items that we need to 'squeeze' into one column, then the data cannot be in first normal form. Let's say that we've decided to

    slap together a database containing information about patients and the (medicinal) drugs they are taking. So we create a table with thefollowing columns, including the primary key "Patient ID Number":

    Patient ID

    Number

    Patient

    NameDrug Trade Name

    Formulatio

    nSize Dose Frequency Side Effect

    Let's try filling in some information..

    Patient ID

    Number

    Patient

    NameDrug

    Trade

    Name

    Formulatio

    n

    Size Dose Frequency Side Effect

    6009315011076 Soap,JoeCarbimazole

    Carbamazepine

    Neomercazole

    Tegretol

    Tab

    Caps

    10mg

    200mg

    30mg

    200mg

    OD

    TDS

    Agranulocytosis

    nil

    6003325011074 Green,Anne CarbimazoleNeomercaz

    oleTab 10mg 10mg OD nil

    Woops. At the intersection of some rows and columns, we've had to fill in two different data items. It's also obvious that there is

    considerable redundancy in the table - the drug Carbimazole (with all the associated information) is represented twice.

  • 8/3/2019 3nf.pharma

    2/4

    Fixing to First Normal Form

    It should be clear that we can fix things by simply introducing a "composite primary key" - we can group the drug and the patient ID

    together as a composite primary key, so now each row has a unique primary key, and at no intersection of row and column do we have

    to put in two data items:

    Patient ID

    NumberDrug

    Patient

    Name

    Trade

    NameFormulation Size Dose Frequency Side Effect

    6009315011076 Carbimazole Soap, JoeNeomercazole

    Tab 10mg 30mg OD Agranulocytosis

    6009315011076 Carbamazepine Soap, Joe Tegretol Caps 200mg 200mg TDS nil

    6003325011074 Carbimazole Green,AnneNeomerca

    zoleTab 10mg 10mg OD nil

    Equally clearly, this is a clumsy fix, and really hasn't changed much. We still have immense data redundancy. We need to go furtherto..

    Second Normal Form

    Note that, although the above table is now in 'first normal form', nothing much has changed. Look at the table carefully, and you'll see

    that there are what we call partial dependencies. In other words, the columns Trade Name,Formulation, and Size depend only on theDrug component of the key, and not on the other part of the key, Patient ID Number. Likewise, thePatient Name depends only on

    the Patient ID Number, and is not dependent at all on the Drug column! To get rid of this problem, we create two new tables, a

    Patient Table:

  • 8/3/2019 3nf.pharma

    3/4

    Patient

    Patient ID Number Patient Name

    6009315011076 Soap, Joe

    6003325011074 Green,Anne

    and a Drug Table:

    Drug

    Drug Trade Name Formulation Size

    Carbimazole Neomercazole Tab10mg

    Carbamazepine Tegretol Caps 200mg

    Finally, we relate the two in a diminished form of our original table, thus:

    PatientRx

    Patient ID Number Drug Dose Frequency Side Effect

    6009315011076 Carbimazole 30mg OD Agranulocytosis

    6009315011076 Carbamazepine 200mg TDS nil

    6003325011074 Carbimazole 10mg OD nil

  • 8/3/2019 3nf.pharma

    4/4

    Third Normal Form

    .. but still we're not finished. Look at the last table carefully. There's an intimate relationship between the the dose and the frequencyof giving a drug. Here's where knowledge of your subject comes in. Many people would be happy to stop at this point. There is no

    absolutely fixedrule that says you have to give your carbamazepine at a dose of 200mg TDS - in fact, if you're religiously doing so,you're probably mistreating a lot of your epileptics. But let's say the whole point of our drug survey is to relate different drug regimensand associated side effect! In this context, we have a strong association between the dose and frequency of a drug. We call such a

    relationship between two non-key attributes a transitive dependency.

    Third normal form is about removing transitive dependencies. How could we do this? Well, we could label each dose + frequency as a

    "regimen", and proceed to break up thePatientRx table into two, thus:

    PatientRx

    Patient ID Number Drug Regimen Side Effect

    6009315011076 Carbimazole R1 Agranulocytosis

    6009315011076 Carbamazepine R3 nil

    6003325011074 Carbimazole R2 nil

    with a newDrugRegimen table:

    DrugRegimen

    Regimen Dose Frequency

    R1 30mg OD

    R2 10mg OD

    R3 200mg TDS