Create Relationships

download Create Relationships

of 13

Transcript of Create Relationships

  • 7/27/2019 Create Relationships

    1/13

    Create Relationships

    In Access, you store data in multiple tables and then use relationships to join the tables. After you have createdrelationships, you can use data from all of the related tables in a query, form, or report.

    Aprimary keyis a field or combination of fields that uniquely identify each record in a table. A foreign keyis avalue in one table that must match the primary key in another table. You use primary keys and foreign keys to join tablestogetherin other words, you use primary keys and foreign keys to create relationships.

    here are two valid types of relationships! one"to"one and one"to"many. In a one"to"one relationship, for everyoccurrence of a value in table A, there can only be one matching occurrence of that value in table #, and for everyoccurrence of a value in table #, there can only be one matching occurrence of that value in table A. $ne"to"onerelationships are rare because if there is a one"to"one relationship, the data is usually stored in a single table. %owever, aone"to"one relationship can occur when you want to store the information in a separate table for security reasons, whentables have a large number of fields, or for other reasons. In a one"to"many relationship, for every occurrence of a value intable A, there can be &ero or more matching occurrences in table #, and for every one occurrence in table #, there canonly be one matching occurrence in table A.

    'hen tables have a one"to"many relationship, the table with the one value is called theprimarytable and thetable with the many values is called the relatedtable. Referential integrityensures that the validity of the relationshipbetween two tables remains intact. It prohibits changes to the primary table that would invalidate an entry in the relatedtable. (or e)ample, a school has students. *ach student can make several payments, but each payment can only be fromone student. he +tudents table is the primary table and the ayments table is the related table.

    +tudents

    +tudent I- ast /ame (irst /ame

    rimary 0ey

    1 2ohn +mith

    3 4ark Adams

    5 6alerie 0ilm

    ayments

    ayment I- +tudent I- Amount -ue Amount aid

    rimary key (oreign key

    1 1 788 7883 3 988 588

    5 5 788 378

    : 3 :88 588

    7 5 378 378

    If you delete +tudent I- 1 from the +tudents table, +tudent I- 1 is no longer valid in the ayments table. ;eferentialintegrity prevents you from deleting +tudent I- 1 from the +tudents table. Also, if the only valid +tudent I-s are 1, 3, and5, referential integrity prevents you from entering a value of : in the +tudent I- field in the ayments table. A foreign keywithout a primary key reference is called an orphan. ;eferential integrity prevents you from creating orphans.To create relationships:

    1.

  • 7/27/2019 Create Relationships

    2/13

    @. Activate the ables tab if your relationships will be based on tables, activate the ueries tab if your relationshipswill be based on queries, or activate the #oth tab if your relationships will be based on both.

    9. -ouble"click each table or query you want to use to build a relationship. he tables appear in the ;elationshipswindow.

    B.

  • 7/27/2019 Create Relationships

    3/13

    Tip:After a relationship has been created between two tables, you must delete the relationship before you canmake modifications to the fields on which the relationship is based. o delete a relationship!

    1.

  • 7/27/2019 Create Relationships

    4/13

    1. $pen a table or query in uery -esign view.3.

  • 7/27/2019 Create Relationships

    5/13

    3.

  • 7/27/2019 Create Relationships

    6/13

    1. $pen a table or query in uery -esign view.3.

  • 7/27/2019 Create Relationships

    7/13

    1. $pen a table or query in uery -esign view.3.

  • 7/27/2019 Create Relationships

    8/13

    1. $pen a table or query in uery -esign view.3.

  • 7/27/2019 Create Relationships

    9/13

    -ate H K3?1@?BBK

    Lreater than

    #etween #etween twovalues,greater than orequal to one andless than or equalto the other

  • 7/27/2019 Create Relationships

    10/13

    1. $pen a table or query in uery -esign view.3.

  • 7/27/2019 Create Relationships

    11/13

    1. $pen a table or query in uery -esign view.3.

  • 7/27/2019 Create Relationships

    12/13

    1. $pen the tables and?or queries you want to use in uery -esign view.3. .@.

  • 7/27/2019 Create Relationships

    13/13

    $nce created, a query can be modified. +imply open the query in uery -esign view and make the changes. You can addcolumns, change the sort order, change the criteria, and make other changes.In uery -esign view, the uery +etup group offers several options that can assist you. Fse the Insert ;ows button toinsert a row in the criteria area.