Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Relationships in Access As you recall, the data in a database is stored in tables. In a relational database like Access, you can have multiple.

Similar presentations


Presentation on theme: "Database Relationships in Access As you recall, the data in a database is stored in tables. In a relational database like Access, you can have multiple."— Presentation transcript:

1 Database Relationships in Access As you recall, the data in a database is stored in tables. In a relational database like Access, you can have multiple tables and you can relate fields in one table to fields in another. For example, a country in the West Africa table could be related to the nationality of the people in the Famous Africans table. Then if you search for information about the country Ghana, you could also see the Famous Africans from Ghana

2 As another example, a book thats been checked out of the library could be related to the student who checked it out. When a librarian looks up information about the book in one table, it is linked to the students information (address, phone number, etc) in the other table.

3 Creating relationships is important because it avoids unnecessary duplication of data. For example, the library need not keep its own list of students addresses. Creating relationships is also more efficient. For example, if a students address changes, it only needs to be updated in one table, and the other tables that are linked to it will have access to the revised data.

4 Relationship Review When working with databases, you may want to access info from several tables at once. To do so, you must create relationships between the tables. Such relationships tell access how to match the info from separate tables.

5 Relationship Review Cont When creating relationships, you always work with two tables at a time. One table is called the primary table and the other is called the related.

6 Types of Relationships Relationships may be one-to-one, one-to many, or many-many. One-to-many relationships are the most common. One table (the parent) can have many matching records in another table (the child).

7 Note Before you create a relationship between tables, it must meet these requirements: Both tables need to be in the same database file. If they are in separate files, you need to import a table from one database file to another (File, Get External Data, Import). Both tables need to have a primary key defined (open the Table, choose view, design view, then click in the field and click the key icon or choose Edit then Primary KEY)

8 Note Cont The two related fields must be of the same data type (number, text, date/time, etc) The data in the two related fields must match. That is, dont enter Ghana in the Country field and Ghanaian in the Nationality field. Use Ghana in both cases.

9 When you fail to join two or more tables, you will produce a query results datasheet in which every record in say table A is joined with every record in say table B. This is called a cross or cartesian product. If you create join fields that do not contain common data, the query results datasheet will show unexpected results.

10 Types of Joins There are three basic types of joins in Access: 1.Inner joins, which are also known as equi-joins 2.Outer joins 3.Self joins

11 Types of Joins Cont An inner join is the default join in Access. Access select only those records from both tables that have a matching value in the fields that joined. If a record in say table A has a value in the join field that is not found in the corresponding field in any of the records in say table B, then that record is not included in the query results.

12 Types of Joins Cont Inner Join Type Table A Table B

13 Types of Joins Cont An outer join includes all the records from one table and only those records in the second table that have matching values in the joined field. We have the Left Outer Join and Right Outer Join.

14 Types of Joins Cont Left Outer Join Type Table B Table A

15 Types of Joins Cont Right Outer Join Type Table A Table B

16 Types of Joins Cont In Access the first Join Type is the Inner Join and the second and third Join Types are Left and Right Outer Joins Respectively.

17 Types of Joins Cont A self join relates the data between records in a single table. For example, if your table records measurements overtime, and each record represent a sampling, you may want to compare the measurement between records.

18 Types of Joins Cont To create a self join, you must add the table to the query twice and join the related fields. By joining the two copies of the same table, you create a self join that combines records from the same table when there are matching values in the joined tables.

19 Types of Joins Cont You can use a self join in any situation in which you need to compare records in the same table to one another.


Download ppt "Database Relationships in Access As you recall, the data in a database is stored in tables. In a relational database like Access, you can have multiple."

Similar presentations


Ads by Google