Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Design. Referential Integrity : data in a table that links to data in another table must always work in such a way that following the link will.

Similar presentations


Presentation on theme: "Database Design. Referential Integrity : data in a table that links to data in another table must always work in such a way that following the link will."— Presentation transcript:

1 Database Design

2 Referential Integrity : data in a table that links to data in another table must always work in such a way that following the link will find a value. Example The names and ID numbers of employees are stored in a table The titles and course codes for courses are stored in a table The ID of an employee is unique for each person (A PRIMARY KEY) and the course code is unique for each course (A PRIMARY KEY). To show that they have attended a course the two key can be stored in a table called Attended. If the Attended table had an ID in it but there was no corresponding employee in the Employee table, the data would make sense and we would say that it “lacked referential integrity”

3 Querying and outputting data When we normalise data we ensure that each table has at least one field that is a primary key Any table may have fields that refer to data in other tables by using the primary key in that table In order to select data we use queries that identify which keys link together and what values are being searched for. In order to output data we can create forms or reports that are populated from the results of the query. This may involve a database engine combined with report generating application or a programming language wrapping the output in HTML. Applications like MsAccess provide the facility to create forms and reports that are automatically generated when a query or table is selected Example query: SELECT * FROM employee, attendscourse WHERE employee.ID = attendscourse.empID

4 Data Integrity: Functionality We can set rules that cascade changes automatically when tables are edited. So updates to keys are migrated to affected tables, deletes can be set to automatically delete dependent data from other tables. We can also set up rules about which keys are linked and this ensures that new records cannot be added to tables unless the data that they are related to already exists in the related table In this example the person with ID 3 is taking a Spinning course but there is no corresponding person with ID 3. referential integrity is broken. Karen’s ID should be a primary key (and therefore automatically set as a “Required” field) but it is missing and this results in the inability of other tables to link to her data. NameID John1 Karen PersonIDCourse 3Spinning 1Pottery


Download ppt "Database Design. Referential Integrity : data in a table that links to data in another table must always work in such a way that following the link will."

Similar presentations


Ads by Google