Presentation is loading. Please wait.

Presentation is loading. Please wait.

AOIT Database Design Unit 3, Lesson 9 Data Integrity Copyright © 2009–2011 National Academy Foundation. All rights reserved.

Similar presentations


Presentation on theme: "AOIT Database Design Unit 3, Lesson 9 Data Integrity Copyright © 2009–2011 National Academy Foundation. All rights reserved."— Presentation transcript:

1 AOIT Database Design Unit 3, Lesson 9 Data Integrity Copyright © 2009–2011 National Academy Foundation. All rights reserved.

2 Physical databases have tables, columns, and rows A table represents an entity A column (or field) represents an attribute A row (or record) represents an instance When database designers talk about physical databases, they refer to the physical components that you can actually see: tables, columns, and rows

3 A database is useless if the data is not accurate, valid, and consistent Keeping a database accurate, valid, and consistent is called maintaining data integrity. If you had an entire season’s track meet results in a database and one runner’s 100-yard-dash score got assigned to another runner, what would happen? If you sent a customer’s order for a dolphin necklace to another customer who had ordered a dolphin ballpoint pen, what would happen?

4 Integrity means whole, complete, and uncorrupted The English word integrity involves the following: Honesty Adherence to a strict moral or ethical code Having the quality of wholeness or completeness Do you see why the term data integrity was coined? How would you define data integrity to someone who already knows the meaning of integrity?

5 Entity integrity checks for duplicate entries in a database If you have a Customers table and the PK is CUSTOMER_ID, entity integrity will ensure that you don’t have two customers with the same ID Access ensures that every instance of a primary key is unique and not a duplicate What do you think happens if you try to enter duplicate data in the primary key? Could you have duplicate data in the other columns? What is the primary key?

6 Access creates a PK index that doesn’t allow duplicates Access uses an index to check that all primary key entries are unique “Indexed” is one of the field properties you can specify for an attribute

7 Access also automatically enforces entity integrity on composite primary keys To create a composite primary key, select the two fields and click Design > Primary Key

8 For composite primary keys, the combination of the two keys is indexed as unique After you create your composite PK, go to the Design tab’s Indexes panel to see how Access has indexed the composite key The individual columns may allow duplicates Entity integrity is enforced only on the combination of the two keys

9 Tables with foreign keys require referential integrity Referential has to do with a foreign key in one table referring to a primary key in another table Integrity has to do with keeping the references intact, whole, and complete What are the foreign keys? What primary keys do they refer to? Why would there be an integrity problem if you deleted a CategoryID because you no longer sold that category of products?

10 A foreign key that doesn’t refer to a primary key is an orphan Here’s how orphan records might occur: 1. You decide to delete Speedy Delivery shipper (SHIPPER_ID 2) 2. The Shippers table has a one-to-many relationship with the Orders table What happens to SHIPPER_ID 2 in the Orders table?

11 Speedy Delivery’s orders become orphans because they do not have a shipper If Speedy Delivery has orders in the Orders table, those orders become orphans when you delete the Shippers record The orders still contain a shipper ID, but the ID is no longer valid, because the row that it references in the Shippers table no longer exists

12 You choose to enforce referential integrity when you define or edit the relationship between PKs and FKs

13 Access offers Cascade Delete and Cascade Update options to override referential integrity In our example, Shippers is the “parent” table (the “one” table in the relationship), and Orders is the “child” table If you specify Cascade Delete, Access automatically deletes a related row in a child table when it deletes a matching row in the parent table Here’s how Cascade Delete works:

14 Cascade Delete and Cascade Update can be dangerous With these options, when you delete or update data that is a primary key, the related foreign key data is also deleted or updated This can be dangerous because you may destroy more data than you wanted to and there is no way to undo the operation For example, if you delete a shipper, you probably want to transfer an order to another shipper, rather than deleting the order

15 Entity integrity and referential integrity keep your data coherent Access automatically enforces entity integrity by requiring that all rows in a table have a unique primary key Referential integrity, which you must specify yourself, ensures that the relationships between primary keys and their foreign keys are maintained


Download ppt "AOIT Database Design Unit 3, Lesson 9 Data Integrity Copyright © 2009–2011 National Academy Foundation. All rights reserved."

Similar presentations


Ads by Google