Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Dan you there?

    Sorry Dan I havent been able to work this out
    am i thinking along the right lines when
    1 table has a list of all the lanuages that are in the database are represented
    table two has my hospitals and their details
    then in the third database how do i make a relationship

    table one has languages and an id next to it -- id 1 language (field name)
    english id 2 language german etc down to the nth language

    table two has an Id number for each hospital
    id 1 Hospital (field name) Central Hospital
    2 south hospital
    nth nth hospital

    in the last table how do i link them?
    i have read about foriegn keys
    Do i include the hospital information in the second table ? i.e telephone
    number etc

    Sorry Dan for all the questions as you know i am a beginner
    Still gotta buy you tat beer - dont let me forget

    quiero mas Guest

  2. #2

    Default Re: Dan you there?

    I ain't Dan but I figure to save you some beer money (I only drink snapps).

    Anyway create the third table with the name LanguagesByHospital (this is a
    relation table).

    It needs a column called Hospital_id and another column called Language_id.

    It is a good idea to also include a third column -- to avoid problems with
    maintanence or expansion.
    Call it iID and make it an autonumber (if using access) or an identity column
    (if using SQL server).

    Also, when using this kind of table it is a good idea to create an index that
    requires the combination of Hospital_id and Language_id to be unique.
    This will save headaches down the road and will also speed up searches.

    Also you would add any data that is relationship specific, like the name of
    the speaker, to this table. (Expand the aforemention index if you do.)


    To create a language entry for a hospital, you would use SQL like this:

    INSERT INTO LanguagesByHospital
    (Hospital_id, Language_id, SpeakerName)
    SELECT
    (Select Hospital_id FROM HospitalTable WHERE HospitalName = 'North Nagasaki
    Neonatal Nursery'),
    (Select Language_id FROM LanguageTable WHERE LanguageName = 'Swahili'),
    'Dale O''Malley'


    To find out which hospitals had Esperanto available, you would use something
    like this:

    SELECT
    Hosp.hospitalName,
    LbyH.SpeakerName
    FROM
    HospitalTable Hosp
    INNER JOIN
    LanguagesByHospital LbyH ON LbyH.Hospital_id = Hosp.Hospital_id
    INNER JOIN
    LanguageTable LangTab ON LangTab.Language_id = LbyH.Language_id
    WHERE
    LangTab.LanguageName = 'Esperanto'


    You can find an introductory article, on why to go through this hassle, at:
    [url]http://www.sqlservercentral.com/columnists/bkelley/normalization.asp[/url] .
    That site also has a forum you can use for SQL help.

    Regards,
    -- Not Dan


    MikerRoo Guest

  3. #3

    Default Re: Dan you there?

    Not dan thanks very much - looks like the snapps are on me - or in my case sake -

    thanks again

    quiero mas Guest

  4. #4

    Default Re: Dan you there?

    I disagree. That paricular 3rd column serves no useful purpose and creates
    extra work. Other columns may be useful in tables with many to many
    relationships, but not that one.

    Originally posted by: MikerRoo
    It is a good idea to also include a third column -- to avoid problems with
    maintanence or expansion.
    Call it iID and make it an autonumber (if using access) or an identity column
    (if using SQL server).




    Dan Bracuk Guest

  5. #5

    Default Re: Dan you there?

    I disagree.
    That iID (could be a datestamp in SQL server) takes no extra work. You
    create it once and then forget about it until it saves your bacon.
    It uses minimal resources and has almost no noticeable impact on performance.

    Its function is as a poor man's (or universal) datestamp. In can be
    invaluable for replication or certain self join queries.
    And, for newbies who may not set up a proper primary key (which in this case
    is a two, or more, column index), it is a critical fallback.


    MikerRoo Guest

  6. #6

    Default Re: Dan you there?

    I appreciate the discussion dan and mike - i guess i have to make a choice - As
    mike points out im a newbee so hard to make an informed choice. Suddenly got
    confusing -

    Ill do some research and try and make an informed choice.

    Thanks to both of you for taking your time to answer

    Regards Mark

    quiero mas Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139