Databse Layout

Discussion in 'Databases - SQL Server 2008 / MySQL' started by lee2006, Feb 11, 2007.

  1. lee2006 Guest

    Hi all have a bit of a design question with regards to a sql server database I am buliding for my site. I am new to database that have more than one table.
    I have a table that contains an establishments information example bellow:

    EstID
    EstName
    EstAdd
    EstPostc
    EstPhone
    EstEmail

    The problem I have is each establishment can have multiple facilities. I have a facilities table as bellow:

    FacilID
    FacilName

    this holds all the avalable facilities

    How do I then link these to the establishment details as an establishment can have many facilities but I want the list of facilities to be pre defined not user entered

    any idea please help

    lee
  2. Nick Irvine Secretly the main man

    You can link the tables by putting an extra field on the Faclities table called EstID. Then you can link the tables by putting the relevant EstID in the EstID field in the facilities table.

    I'm not sure what you mean about the pre defined facilties.
  3. lee2006 Guest

    Hi there

    I did think of that but then I tought the facilities name would have to keep being repeated as each establishment has multiple facilities and I want a table the contains the list of facilities that the user of the site can choice and add to there establishment, soory im a bit naff at explaining this

    I came up with
    establishment table
    EstID
    EstName
    EstAdd
    EstPostc
    EstPhone
    EstEmail

    linktable
    Esid
    Facilid

    facilities table
    FacilID
    FacilName

    is this plausable haveing a table in the middle to relate the selected facilities in the facilities table to the establishment table

    hope you can help

    lee
  4. Nick Irvine Secretly the main man

    Yeah sure, I understood you. You are correct, that is what you need to do. Forgive me did not explain myself clearly.

    Create one table, facilities and have the following:

    facid
    facname

    In the facilities table add all the unqiue facilities, only have to enter each facilitiy once.

    Then you can have another table called estblishments. In this table put all the details you want to include about the establishment.

    EstID
    EstName
    EstAdd
    EstPostc
    EstPhone
    EstEmail

    Then, like you say have a middle table that acts as a go between. As you say:

    linkid
    Esid
    Facilid

    This process I always use and does work well.

    You may want to add another field to the links table called linkid, this can make it easier for you to delete associations later.

    Hope thats clearer.
  5. lee2006 Guest

    That what I need

    Thanks alot for your help

    Appeciated

    lee

Share This Page