|
Linking tables (creating relationships)Right now, the database consists of three small tables: tablePerformers, tableVenues and tableEvents. If you think about it, it makes sense for these three types of information to be separated.
In the next series of steps, you will be linking these tables to create relationships between them: When you link tables in a database to create relationships between them, you have a relational database. Relational databases can be very efficient ways to store and retrieve information. 1. Close all of your tables by clicking on the x to the right of the tabs: 2. Click on the Database Tools tab and click on the Relationships icon: 3. You'll get a popup box titled Show Table with a list of your tables. Select a table name and click the Add button (if you click on one twice accidentally, it will be added twice, but you can select it and delete it later). Do this for all 3 tables. 4. Close the Show Table popup Next, you're going to create two relationships:
5. Click on PerformerID, hold the mouse key and drag it to the ID field in tablePerformers You'll get this: 6. Click on the Enforce Referential Integrity box, and then click the Create button. You should see this: The line shows that there is a relationship between these two fields (and therefore between these two tables). The infinity sign shows that there can be many records in tableEvents that correspond to a single record in tablePerformers (in other words, a performer may perform at many events). This is called a many-to-one relationship. RELATIONSHIP TYPES many-to-one relationship one-to-one relationship many-to-many relationship 7. Now click VenueID and drag it to ID in tableVenues. Again, check the Enforce Referential Integrity box and click the Create button to get this: Now that the relationships are in place, we'll fill in tableEvents. There will be three events: 8. Open tableEvents (click its name on the left side of the screen) and start by typing in the three concert dates: Next you'll fill in PerformerID and VenueID values. 9. The performer at the May 24, 2008 concert is Ladytron, so open tablePerformer and find the ID is for Ladytron. (in this screenshot, the ID for Ladytron is 6 (but yours might be different): 10. Return to tableEvents and enter that number in the PerformerID field. 11. Follow the same steps to fill in the values for the other PerformerID fields, then open tableVenues to find the correct values for the VenueID fields and fill those in as well. Now our database is fully functional and we set up to pull information from it | |
Introduction | Create Database | Tables & Keys | Data Types | Link Tables | Basic Query | More Queries |
next page |