Presentation is loading. Please wait.

Presentation is loading. Please wait.

11 3 / 12 CHAPTER Databases MIS105 Week-9/ Lec02 Irfan Ahmed Ilyas.

Similar presentations


Presentation on theme: "11 3 / 12 CHAPTER Databases MIS105 Week-9/ Lec02 Irfan Ahmed Ilyas."— Presentation transcript:

1 11 3 / 12 CHAPTER Databases MIS105 Week-9/ Lec02 Irfan Ahmed Ilyas

2 11 02/3/2002Prepared By: Irfan Ilyas2 Lecture Objectives Data Integrity Constraints FOR Accurate Data Entry –Single Table Integrity Constraints –Referential Integrity Constraints Significance of Table Relationships –Controlling Referential Integrity –Building Queries Referential Integrity Maintenance Approaches –One-to-One Relationship Maintenance –One-to-Many Relationship Maintenance

3 11 02/3/2002Prepared By: Irfan Ilyas3 Types of Data Integrity Constraints Single Table Constraints [ Entity Integrity ] Data type constraints –Field can only accept numbers or characters. –DBMS Implementation: Specifying field data type/ size. Primary key constraints –No two records have the same value in the primary key field. –No primary key value in any record should be left blank (empty). –DBMS Implementation: Specifying table’s primary key. Field value constraints –The value must be satisfying some criteria. –For example, salary can not be less than $100 etc. –DBMS Implementation: Specifying field validation rule.

4 11 02/3/2002Prepared By: Irfan Ilyas4 …. Data Integrity Constraints Related Table Constraints [ Referential Integrity ] –Specifies that a record in one table must be related to the records in other tables, thus exhibiting a particular relationship between the two tables –For example, In a University database STUDENT, COURSE, DEPARTMENT, DORM Each record in STUDENT is related with the records in COURSE, DORM and DEPARTMENT The details of this relationship can be understood by the surrounding (university) environment.

5 11 02/3/2002Prepared By: Irfan Ilyas5 Relationship Types Types of Relationships (in real life situations) –One to one (1:1) relationship A record –in the source file must have zero or only one record in the related file. –in the related file must have only one record in the source file. –DBMS Implementation: Establishing Relationship –One to many (1:M) relationship A record –in the source file must have zero or one or many records in the related file. –in the related file must have only one record in the source file. –DBMS Implementation: Establishing Relationship DORM STUDENTDEPARTMENT STUDENT

6 11 02/3/2002Prepared By: Irfan Ilyas6 … Relationship Types Many to many (M:M) relationship –A record –in the source file must have zero or one or many records in the related file. –in the related file must have zero or one or many records in the source file. –DBMS Implementation: »The M:M relationship is decomposed into two 1:M relationships »A third table is used as an intermediate place (many table) for data records, linked with both one-tables STUDENT COURSESTUDENT GRADE COURSE

7 11 02/3/2002Prepared By: Irfan Ilyas7 Relationship Significance Significance of defining Relationships –Implementation of Integrity constraints Any attempt of entering invalid data values will be checked/ rejected automatically by the DBMS. However, it can not check all possible constraints. –For example, a grade letter A entered wrongly as C cannot be checked but entered as X (invalid entry for grades) can be rejected. –More efficient/ accurate data retrieval for Queries For example, student grade list query needs data records from three tables: STUDENT, GRADE, COURSE Established relationships will make the retrieval efficient and accurate.

8 11 02/3/2002Prepared By: Irfan Ilyas8 Requirements for Establishing A Relationship Field Repetition –A field (primary key) from one-table is repeated in many-table as a foreign key. –The fields should be the same in data type and size. –The names of the fields could be different in each table.

9 11 02/3/2002Prepared By: Irfan Ilyas9 …Requirements for Establishing A Relationship

10 11 02/3/2002Prepared By: Irfan Ilyas10 Referential Integrity Maintenance Requirement (1:1 Relationships) –Each record in source-table should have zero or one records in related-table. –Each record in related-table must have a corresponding record in source-table. 1:1 Example: DORM STUDENT

11 11 02/3/2002Prepared By: Irfan Ilyas11 …Referential Integrity Maintenance (1:1) Related Table Changes –Deletion requests in related-table are always acceptable. –Modification requests in many-table are accepted when foreign key is not touched. rejected when a value is used in the foreign key (linked field) which doesn’t exist in one-table.

12 11 02/3/2002Prepared By: Irfan Ilyas12 …Referential Integrity Maintenance Source Table Changes –Deletion requests For a record which has no related record in the related table - Accepted For a record which has related record in the related table –Approach#1: Rejected –Approach#2: Accepted, with the related record deleted automatically. –Modification requests Primary key value is not touched – accepted. Primary key value is changed. –For a record which doesn’t have a related record in the destn table - Accepted –For a record which has a related record in the destn table »Approach#1: Rejected »Approach#2: Accepted, with the related record updated automatically.

13 11 02/3/2002Prepared By: Irfan Ilyas13 …Referential Integrity Maintenance Requirement (1:M Relationships) –Each record in one-table should have zero or many records in many-table. –Each record in many-table must have a corresponding record in one-table. 1:M Example: DEPT STUDENT

14 11 02/3/2002Prepared By: Irfan Ilyas14 … Referential Integrity Maintenance Many-table changes. –Deletion requests in many-table are always acceptable. –Modification requests in many-table are accepted when foreign key is not touched. rejected when a value is used in the foreign key (linked field) which doesn’t exist in one-table.

15 11 02/3/2002Prepared By: Irfan Ilyas15 … Referential Integrity Maintenance One-table changes. –Deletion requests For a record which has no related record in the many table -Accepted For a record which has related record in the many table –Approach#1: Rejected –Approach#2: Accepted, with all related records deleted automatically. –Modification requests Primary key value is not touched – accepted. Primary key value is changed. –For a record which has no related record in the many table -Accepted –For a record which has related record in the many table »Approach#1: Rejected »Approach#2: Accepted, with all related records deleted automatically.

16 11 02/3/2002Prepared By: Irfan Ilyas16


Download ppt "11 3 / 12 CHAPTER Databases MIS105 Week-9/ Lec02 Irfan Ahmed Ilyas."

Similar presentations


Ads by Google