Your SlideShare is downloading. ×
S2  intersection table pdf
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

S2 intersection table pdf

586
views

Published on


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
586
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Copyright © 2009 Bahn, D., Tang, H. & Yardley, A. All Rights Reserved. ISBN: 978-1-936203-03-1 Systems Analysis and Design Learning Module Series #2 Document versionCreating an Intersection Table in a Relational DatabaseOverviewIn this tutorial we will add two additional tables to the COURSE DATABASE that we created in “SystemsAnalysis and Design, Learning Module Series #1, Creating a Relational Database.”The first new table (the Student table) will contain a list of students who are taking some of the sectionsassociated with courses in our original database. Our goal is to be able to store (and accurately query) theattribute “final_grade”, which is a functional dependency of Student and Section together: { (student, section)  final_grade }Since a given student may be taking many sections; while a given section may be associated with manystudents, there is no unambiguous way of identifying which set of records in one table belongs to a single recordin the other. It comes out that neither table can effectively contain the attribute final_grade.As a result, the relational model does not support the direct implementation of many-to-many relationships andthe only solution is to break the many-to-many relationship into a pair of binary, one-to-many relationships.This is achieved by introducing a third table to the pattern. These “third” tables have various names, but aremost commonly referred to as either “intersection”, “composite”, or “cross-reference” tables. 1
  • 2. Copyright © 2009 Bahn, D., Tang, H. & Yardley, A. All Rights Reserved. ISBN: 978-1-936203-03-1The new intersection table (the Registration table) then, will be utilized to eliminate the many-to-manyrelationship that exists between students and sections. The Primary Keys of the Student and Section tables,respectively, are both placed into the intersection table as a Foreign Key, such that the Primary Key of theintersection table is a composite of the two Foreign Keys. Additionally, it will contain the attribute final_grade.Creating the Student Table 1. Open the Course Database (you created in Tutorial I) in MS Access 2007. From the Table Tools palette, select the Create tab, and click on Table. 2. Under the All Tables pane, right click on Table1 : Table and select Design View from the drop down menu . (In the Save As dialog box, under Table Name, type Student and click OK . 2
  • 3. Copyright © 2009 Bahn, D., Tang, H. & Yardley, A. All Rights Reserved. ISBN: 978-1-936203-03-1  3. (a) Under the Student tab, under Field Name, enter Field (or column) names as follows: student_ID (primary key), last_name, first_name, address, city, state, zip and ssn. (b) Under Section tab, under Data Type, click the down-arrow for the student_ID to select Text.4. When you are done, right-click on the Student tab and click Save on the drop down menu.5. Under All Tables, double-click on Student : Table. Enter the data as shown below. 3
  • 4. Copyright © 2009 Bahn, D., Tang, H. & Yardley, A. All Rights Reserved. ISBN: 978-1-936203-03-1 6. When you are done, right-click on the Student tab and click Save on the drop down menu 7. Right-click again and select Close All … and Yes to “save changes to the layout of table Student”.Creating the Registration (intersection) Table 8. From the Table Tools palette, select the Create tab, and click on Table. 4
  • 5. Copyright © 2009 Bahn, D., Tang, H. & Yardley, A. All Rights Reserved. ISBN: 978-1-936203-03-19. Under the All Tables pane, right click on Table1 : Table and select Design View from the drop down menu . (In the Save As dialog box, under Table Name, type Registration and click OK .  10. (a) Under the Student tab, under Field Name, enter Field (or column) names as follows: student_ID, section_ID and final_grade. (b) Under Section tab, under Data Type, click the down-arrow for the student_ID to select Text.11. Holding down the Ctrl key, click both of the blue boxes preceding the rows (highlighted here in red) for both student_ID and section_ID. Then click the Primary Key button on the Design palette. 5
  • 6. Copyright © 2009 Bahn, D., Tang, H. & Yardley, A. All Rights Reserved. ISBN: 978-1-936203-03-112. Right-click on the Registration tab and select Save.13. Enter the data for student_ID, section_ID and final_grade as shown below. 6
  • 7. Copyright © 2009 Bahn, D., Tang, H. & Yardley, A. All Rights Reserved. ISBN: 978-1-936203-03-114. Right-click on the Registration tab and select Save from the drop down menu.15. Right-click again on the Registration tab and select Close All from the drop down menu. 7
  • 8. Copyright © 2009 Bahn, D., Tang, H. & Yardley, A. All Rights Reserved. ISBN: 978-1-936203-03-1Creating relationships between the tables 16. From the Database Tools palette, click on the Relationships button. 17. Under the All Tables pane, click on the Section : Table to highlight it and then drag and drop it over onto the Relationships view. 18. Repeat this step for the Student : Table and the Registration : Table. Then re-arrange the tables so that the Registration (intersection) Table is located in the middle. 8
  • 9. Copyright © 2009 Bahn, D., Tang, H. & Yardley, A. All Rights Reserved. ISBN: 978-1-936203-03-119. To join the tables together with referential integrity, first highlight section_ID in the Registration table (shown above), then drag this section_ID attribute to the left over to the Section table, dropping it on top of the section_ID attribute there. When the Edit Relationships dialog box appears, check all three check boxes: the Enforce Referential Integrity, Cascade Update Related Fields and Cascade Delete Related Records check boxes; and click the Create button.20. Then, highlight student_ID in the Registration table (shown below), and drag this student_ID attribute to the right over to the Student table, dropping it on top of the student_ID attribute there.21. When the Edit Relationships dialog box appears, check all three check boxes: the Enforce Referential Integrity, Cascade Update Related Fields and Cascade Delete Related Records check boxes; an click the Create button. 9
  • 10. Copyright © 2009 Bahn, D., Tang, H. & Yardley, A. All Rights Reserved. ISBN: 978-1-936203-03-1 You should now have successfully linked all three tables together, having created two binary one-to- many relationships constrained with referential integrity as shown below.22. Right-click on the Relationships tab and click Save from the drop down menu. 10
  • 11. Copyright © 2009 Bahn, D., Tang, H. & Yardley, A. All Rights Reserved. ISBN: 978-1-936203-03-1 23. Right-click again on the Relationships tab and click Close All from the drop down menu.Querying the database 1. From the Create Palette, select Query Wizard. 2. At the New Query screen, accept the default Simple Query Wizard by clicking OK. 11
  • 12. Copyright © 2009 Bahn, D., Tang, H. & Yardley, A. All Rights Reserved. ISBN: 978-1-936203-03-13. The Simple Query Wizard displays. Under Tables/Queries, click the drop down arrow to select the Table : Registration. Then transfer final_grade from Available Fields to Selected Fields by clicking the arrow show below in the red box4. Under Tables/Queries, click the drop down arrow to select the Table : Student. Transfer last_name and first_name from Available Fields to Selected Fields by clicking the arrow as before. 12
  • 13. Copyright © 2009 Bahn, D., Tang, H. & Yardley, A. All Rights Reserved. ISBN: 978-1-936203-03-1 5. Click the Finish button to see the results of the query below.Conclusion 13
  • 14. Copyright © 2009 Bahn, D., Tang, H. & Yardley, A. All Rights Reserved. ISBN: 978-1-936203-03-1In this tutorial, we learned how to use an intersection table (the Registration table) to eliminate the many-many relationship between student and sections, and effectively link the tables together accordingly withreferential integrity. We then successfully performed a query leveraging this implementation. Systems Analysis and Design Learning Module Series #2 Document versionCreating an Intersection Table in a Relational Database 14

×