Relational databases involve multiple related tables. There are three main types of relationships: one-to-one, one-to-many, and many-to-many. Foreign keys link tables and enforce referential integrity by ensuring related data remains consistent. The Relationships window is used to define relationships between tables by selecting primary and foreign key fields.
2. Relational Databases Have more than one table where tables are related to each other One to one One to many Many to many A combination of fields may be used for the table’s primary key
3. One to Many Relationships Each table contains data about a specific subject (customers, loans) Each table on the ‘one’ side has a primary key Primary key of the “one” table is a foreign key in the many table
4. Many to Many Relationships Two tables are related, but can have many records in each table in common One student can attend many courses; one course can be attended by many students Implement a many to many relationship by creating a pair of one to many relationships with a third table Third table is often referred to as a “join” or “junction” table Entries in the join table point to rows in the original tables
5. Foreign Key A foreign key points to a record in another table Foreign key “looks like” the related primary key Same number of fields Data types for each field must match Field names don’t matter
6. Referential Integrity Makes sure that the records in related tables are consistent Must have a customer in the customer table for an order assigned to that customer Avoids “orphans” Cannot delete a record or change the primary key in the one table when associated records are in the many table, unless have cascade delete and cascade update enabled
7. Editing Data Making new entries, changing existing entries, and deleting rows are all affected by referential integrity A customer can be added at any time Must have a customer before a loan can be entered and associated with a customer Referential integrity doesn’t require entry into a foreign key Can delete a loan at any time, but can only delete a customer if they don’t have any loans (assuming no cascade delete)
8. Cascading Changes When referential integrity is enforced can choose to include Cascade Update and/or Cascade Delete Cascade update passes changes to the primary key of the “one” table to the related rows in the “many” table Cascade delete removes rows from the “many” table when a primary key (row) is deleted from the “one” table
9. Relationships Window Where relationships between tables are created and defined Related fields must have the same data type Autonumber is related to number field with long integer field size The one table has a 1 next to it; the many has a next to it
10. Autolookup Queries Use queries to automatically look up data from related tables Must contain the foreign key from the many table Can add, change or delete data in the source tables