Presentation is loading. Please wait.

Presentation is loading. Please wait.

Building a database. Implementation of desirable features Integrity –A field’s validation can be declared when the field is declared. If this validation.

Similar presentations


Presentation on theme: "Building a database. Implementation of desirable features Integrity –A field’s validation can be declared when the field is declared. If this validation."— Presentation transcript:

1 Building a database

2 Implementation of desirable features Integrity –A field’s validation can be declared when the field is declared. If this validation is used, then the integrity of the field remains intact. E.g. date, haulage container, payroll/student number. –Entity integrity - No attribute participating in the primary key of a base relation is allowed to accept null values. You cannot make a phone call without a phone number. –Domain constraints - what are the possible valid values that can be used?

3 Referential integrity –Through the propagation and use of foreign keys, no detail can be created where a master is needed, nor can a master be deleted without consent to the deletion of the details –E.g. I cannot order stock unless I know who the supplier is and how to contact the company. If I add a stock item to my database without a supplier, I cannot order stock.

4 Implementation of desirable features Data independence –The implementation of relational databases causes the external and conceptual schema to be data independent. The internal schema and the physical level are data dependent. Controlled redundancy –The relational model reduces redundancy at the conceptual level, because it is in third normal form.

5 Building tables Use primary keys Put the tables with ONLY primary keys in first. –This is the first layer. Put the tables that reference those tables in next. –This is the second layer. –This layer uses the keys of the first layer as FOREIGN keys. –The second layer cannot be placed until the first layer is complete. See the Joe’s Yard example following:

6 Required new data structure

7 Hierarchy of data structure

8 Layers of tables The tables Customer, Staff and Supplier have only primary keys. They are the foundation layer. Layer 1. The tables COrder, Stock and SOrder have foreign keys that only reference the foundation layer. They are Layer 2. COrderline and Sorderline depend on the tables in Layer 2. They are layer 3.

9 Analogous to building bricks

10 Layer 1 The customer table is added, with key CustomerId, the Staff with key StaffNo and the Supplier with key SupplierId.

11 Layer 2 COrder Stock SOrder CustomerStaff Supplier The stock and the sOrder depend on the Supplier, both having foreign key SupplierId. The COrder depends on BOTH Staff and Customer, having foreign keys StaffPaid, StaffIssued and CustomerId.

12 Layer 3 SupplierStaff Customer COrder Stock SOrder Both the sorder line and the corder line depend on the stock, having stockcode as a foreign key and part of their key. cOrder line depends on Corder. Sorder line depends on SOrder

13 The built database

14 Recap Look back at the blocks. –The table creates are the structure or the framework - i.e. the architect’s drawing –The inserts are like the bricks. You cannot insert into a table unless there is supporting data in the table on which it depends. Do –Creates starting with the one(s) with no dependents –Inserts starting with the one(s) with no dependents –Deletes starting with the one(s) on which no other depends –Drops starting with the one(s) on which no other depends


Download ppt "Building a database. Implementation of desirable features Integrity –A field’s validation can be declared when the field is declared. If this validation."

Similar presentations


Ads by Google