design database

  • i am desiging database and i need answer.

    for example i am getting flat file ,which contains pharmacy into and patient info

    pharmacy :

    pharmacyid primary key

    name

    patient:

    patientid primary key

    firstname

    lastname

    now they dont have any relation between them,

    i can have multiple record of patients from same pharmacy, that i need to store, so if there is pharmacyid is primary key, how can i store tha record.

    similarly i can have multiple records for same patient from different pharmacy.

    what should i do

    please help me with design, what kind of relation i need to make,do i need to create third table

  • The basic design is quite simple. You have to create an interim table that has the primary key from patient and the primary key from pharmacy. That creates the many to many join that you need.

    Unfortunately, depending on how the data is coming from your pharmacy, loading this could be tricky. Are the primary keys for the patient unique across pharmacies? Or is it only unique within a pharmacy? If it's only unique within a pharmacy, then you have to have some other method of identifying patients. If all you have is first and last name, you're in trouble. There can be more than 'Li Wong' so just relying on the name is going to hurt you. With that other unique constraint you can just look up the primary key from the person as you perform the loads and put them into the interim table.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply