Hands-On Microsoft Access: A Practical Guide to Improving Your Access Skills
| In Chapter 2, "Database Design," you developed tables and fields for the Classic TV database. In Chapter 3, you identified the existing relationships between tables and developed the final field list shown in Table 4.1. (If you haven't read these two chapters, I strongly encourage you to do so before proceeding.)
When you identified all the relationships in the database, you found that some tables had many-to-many relationships. Recognizing the problems many-to-many relationships pose, you resolved them by creating linking tables. The new tables comprised two one-to-many relationships. No tables in the Classic TV database have one-to-one relationships. Thus, all the tables are on either side of one-to-many relationships. Using the Relationships window, you can formally establish these one-to-many relationships. Table 4.2 is a chart of the one-to-many relationships in the Classic TV database. The matrix shows the relationships the tables on the x-axis have with the tables on the y-axis. For example, viewing the relationship between the Genres and Programs tables in the first row, you can say Genres is on the one side and Programs is on the many. (Don't worry much about understanding this tableyou will soon see a figure that will make these relationships much clearer.)
Viewing Relationships in the Relationships Window
A tour of all the features of the Relationships window will be much more meaningful to you after you create some relationships. But an overview of a typical relationships scheme should be useful now, just so you can see what you're trying to accomplish. The Relationships window contains field lists of the various tables in the database (see Figure 4.1). All the relationships of the Classic TV database have been established with referential integrity enforced (I'll explain what that is soon) and are currently displayed. The primary keys of the tables are in bold. The table on the "one" side of the relationship has a 1 next to its primary key. An infinity sign next to the foreign key in the related table indicates that it's on the "many" side. Figure 4.1. The Relationships window, with all the relationships of the Classic TV database displayed.
As one example, Genres and Programs have a one-to-many relationship. There is a 1 next to GenreID, the primary key of the primary table. In the related table of Programs, there is an infinity sign next to the foreign key GenreID. All the tables have at least one relationship with one other table in the database. Thus, you can combine values from any of the tables through the nexus of relationships that exists among them. As you will see in succeeding chapters, this capability to bring values together is central to manipulating and massaging data in an Access database.
Creating a Relationship in the Relationships Window
Let's start by creating a plain vanilla relationship in the Relationships window. Download the ClassicTVChap4.mdb database from the companion website at www.awprofessional.com/title/0321245458 to a convenient folder on your hard drive and open it.
Now let's see how one of the available options, referential integrity, affects this relationship. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Категории