Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×

Creating relationships with tables

Próximo SlideShare
Database Relationships
Database Relationships
Cargando en…3

Eche un vistazo a continuación

1 de 22 Anuncio

Más Contenido Relacionado

Presentaciones para usted (20)

A los espectadores también les gustó (20)


Similares a Creating relationships with tables (20)

Más reciente (20)


Creating relationships with tables

  1. 1. <ul>Creating Relationships with Tables </ul>
  2. 2. <ul>The word “relationship” is the key to the power of Open Office Database and other Relational Database Management System (RDBMS)s. The ability to create and act on relationships between tables is the real power of relational databases. </ul>
  3. 3. <ul>Relational databases use fields called Key fields , which are common among one or more tables to establish these relationships. There are three ways of relationships can be created. They are: </ul><ul><li>One-to -one
  4. 4. One-to-many .
  5. 5. Many-to-many </li></ul>
  6. 6. <ul><li>One-to -one: For every record in one of the tables, one corresponding record exists in other table.
  7. 7. One-to-many: For each record in a table, many corresponding records may exist in the related table.
  8. 8. Many-to-many: For each record in table A, many records may exist in table B; or for each record in table B, many records may exist in table A. Many-to-many should not exist in a well-designed database. </li></ul>
  9. 9. <ul>How to Create Relationships while Creating Tables </ul><ul>You can define relationships either while creating a table or afterward. Both tables must exist in database in order for you to define a relationship. </ul>
  10. 10. <ul>Using the Table Wizard </ul><ul>An easy way to create a new table that is based on a predefined template using Table Wizard. It is used to create a table to store customers and a table to store orders to create a relationship between students Info or grade table. Follow these steps: </ul><ul><li>Start Access with a blank database. Name the database Relationship Example. </li></ul>
  11. 11. <ul>2. Click the New button on the Tables tab of the Database window. Select the Table Wizard from the list that appears, then click OK. 3. On the first dialog box of the wizard, choose students from the Sample Tables list box. Then move all the fields in the Sample Fields list box to the Fields in My New Table list box . 4. Click the >>button. The dialog box should appear identical to the one show below: </ul>
  12. 12. <ul>Figure Shows the initial dialog box of the Table Wizard for creating the new student table. </ul><ul>5. Accept the default on the next dialog box by clicking Next . Finally, accept the defaults on the last dialog box and then click Finish. The Students Table Datasheet view appears, close <li>the window and return to the Database window. </li></ul>
  13. 13. <ul>You can add the Students Grade table in a similar manner. Because an existing table is in the database, however, the Table Wizard provides an additional dialog box. In this dialog box, you can establish a relationship between the Students Info table. Follow these steps to create the Students Grade Table , and establish <li>the relationship: </li></ul>
  14. 14. <ul><li>Click New , with the Tables tab active in the database window.
  15. 15. Select the Students Grade table from the Sample Table list. Select all fields from the Sample Fields list by clicking the >> button. Click Next.
  16. 16. Accept the defaults in the next dialog box. Click Next.
  17. 17. The dialog box appears, Access has already assumed that a relationship exists between the Students Info and Students Grade tables , thanks to the Student ID field that appears in both tables. </li></ul>
  18. 18. <ul>Using the Toolbar </ul><ul>You are going to create the Students Grade table and afterwards relate this table to Students Info table based on their common field – Students ID . The Student Info table provides the general information about a particular student, and the Student’s Grade table will provide the necessary data to find his average. </ul>
  19. 19. <ul><li>Open the Students Info Database.
  20. 20. Click Table tab from the Database Window , then click New button.
  21. 21. Choose the Design View button and click OK.
  22. 22. Define the following fields and Field Properties . </li></ul><ul>Set the Students ID . Field set the Field Size to Byte . The remaining field creates their Field Size Property to Long Integer and set the Decimal Places property to 2. 5. Click the File menu, and choose Save . 6. Type Students Grade as the name of the Table, from the Table Name box of the Save as dialog box. 7. Click on the OK button. </ul>
  23. 23. <ul>Define Relationships </ul><ul>Once you entered and set up different table for each subject in your database, you have to find ways to tell MS Access how to bring back together that information again. You have to do the following: </ul>
  24. 24. <ul><li>Define relationships between your tables.
  25. 25. Create queries, forms and reports to display information from several tables quickly.
  26. 26. The coordination must be established between tables.
  27. 27. Relationship works by matching data in key fields—usually a field with the same name in both tables using the Primary key.
  28. 28. For example: Faculty Table can create a relationship with Faculty Load table using the Faculty ID fields. </li></ul>
  29. 29. <ul>How to Create Relationship Using Tools </ul><ul><li>Click the Tools menu.
  30. 30. Select the Relationship command. The Relationship window opens, a Show Table dialog box appears on your screen.
  31. 31. Click the Show Table button if the table for which you want to define does not show up.
  32. 32. The Show Table list is highlighted. Click the Add button.
  33. 33. Close the Students Info. </li></ul>
  34. 34. <ul>6 . The two tables and their fields open for the Relationship window. Position the mouse pointer to the Students ID of the Students Info table. 7. Drag the field to the Student ID field of the Students Info to Students ID of the Student Grade table and release it. 8. Click on Create button, to create a line between these two tables. 9. Close the Relationship window by clicking the Close command from the File menu. 10. Click the Next dialog box to yes button to save the layout changes to the Relationship window. </ul>
  35. 35. <ul>To store your data, create one table for each type of information that you track. To bring the data from multiple tables together in a query, form, report, or data access page, define relationships between the tables. </ul>
  36. 36. <ul>The Two Types of Relationship Created </ul><ul><li>A Many-to-many Relationship </li></ul><ul>means if both related fields are part of the primary key for its table. </ul><ul><li>One-to-many Relationship </li></ul><ul><ul><li>means the field form the other table (the look up table) is that table’s primary key. The Lookup table is the table on the ‘one’ aside of the relationship, whereas the base table is on the ‘many’ side. A record in Table 1 could have many matching records in Table 2, but a record in a Table 2 has only one matching record in Table 1. </li></ul></ul>
  37. 37. <ul>One Supplier </ul><ul>Can supply more than one product </ul><ul>But each product has only one supplier </ul><ul>Figure 3 Shows a sample of many-to-many relationship </ul>
  38. 38. <ul>This query retrieves the company name, city, order ID, and required date information for customers in London whose orders were required in April </ul><ul>Note : You should close any open Table Datasheet or Design windows <li>before modifying any of the relationships in the Relationships window. </li></ul>
  39. 39. <ul>How to Open the Relationships Window If you’re opening the Relationship window for the first time for this database, or if these relationships haven’t been saved yet in previous uses, a blank Relationships window appears. The Relationships window display tables and the relationships that have been defined between those tables. The relationships are shown by solid lines connecting the key fields of the tables. Add table to the layout using the Show Table dialog box. Close the Show Table dialog box. Choose Relationships1 Shown Direct </ul>
  40. 40. Prepared by: Mrs. Jennis N. Articona ICT Teacher MPNAG