1 / 9

ISP 121

ISP 121. Access Normalization and Relationships. Normalization. Say we’re operating a pet day-care and we need to keep information on our pets/customers. What happens when a customer has more than one pet? Create a separate table for just the pets. How do you link the two tables together?.

cahil
Télécharger la présentation

ISP 121

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ISP 121 AccessNormalization and Relationships

  2. Normalization • Say we’re operating a pet day-care and we need to keep information on our pets/customers. What happens when a customer has more than one pet? • Create a separate table for just the pets. • How do you link the two tables together?

  3. Normalization Example Pet Information(originally) Customer ID (primary key) Customer Last NameCustomer First Name Customer Address Customer City Customer State Customer Zip Customer Phone these fields repeat 1 to n times Pet ID Type of Animal Pet Name Breed Color Weight Height Customer Table Customer ID (primary key) Last NameFirst Name Address City State Zip Phone Pet Table Pet IDType of AnimalPet NameBreedColorWeightHeight Customer ID (not a primary key here!) Relationship Primary Key in Customer Table? Foreign Key in Pet Table? Is there a primary Key in Pet Table?

  4. Another Example Student Records Student ID (primary key) Name Address City State Zip Phone these fields repeat 1 to n times Class Name Grade Number Credits Major Minor Degree Sought Student Info Student ID Name Address City State Zip Phone Major Minor Degree Sought Grades Class Name Grade Number Credits Student ID After Before

  5. Let’s Try This One In Access Customer ID Customer Last Name Customer Phone Customer Address Customer City Customer State Customer Zip following fields repeat 1 to n times: Sales Transaction Date Sales Amount Let’s first create the two tables using paper and pencil, then when we know they are correct, let’s enter the tables into Access.

  6. Relationships • Remember that relational databases split data between two or more tables. To link these tables, we use a foreign key to tie them together. • Usually the linking field is the primary key in one database, but not a primary key in another (if it is cross-reference by another table, it is considered a foreign key). • Tables don't become magically related... you will have to relate them (or verify that Access has related them correctly).  Usually you only want to put tables in a database that you will relate in some way. • Linking fields must be the same data type. • Types of Relationships: • One-to-one • One-to-many • Many-to-one • Many-to-many (not an option!!)

  7. Relationships • Three important thoughts about linking tables: • You can link only tables that are in the same database. • You can link queries to tables, but that’s unusual. • You need to tell Access how your tables are related up front – it is a formal process.

  8. Relationships • Creating Formal Relationships: • Click on the Relationships button on the toolbar. • Click on the Show Table button on the toolbar. Add tables if needed by choosing add. Click close after you are done. • Decide which two tables you want to link. Put the mouse pointer on the field you want to link in the parent table (which will be the primary key of that table) and hold the left mouse button down.  While holding the mouse button, slide the mouse from one linking field to the other. • Choose Enforce Referential Integrity (ensures that relationships between records in related tables are valid and the you don't accidentally delete or change related data). Then choose create.  Repeat.

  9. Why do we have relational databases? • Eliminates redundancy • Makes adding data easier • Allows for more secure access to only parts of the data

More Related