chapter three ( relational data model) objectives introduction to relational data models. advantages...
TRANSCRIPT
![Page 1: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/1.jpg)
Chapter Three( Relational Data Model)
Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational Data Model. Keys. What are a good BD Design?
![Page 2: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/2.jpg)
2
Relational Data Model: Developed by Codd in 1970. Conceptually simple. Based on mathematical set theory.
![Page 3: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/3.jpg)
3
Relational Data Model: Most important advantage of the
RDBMS is its ability to hide the complexities of the relational model from the user.
![Page 4: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/4.jpg)
Relational Database Models:
Data are represented as a set of tables.
![Page 5: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/5.jpg)
5
Structure A set of tables ( Relations). Each relation has a unique name. Each relation has a set of
attributes. Each relation has a set of tuples.
![Page 6: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/6.jpg)
6
Restriction on Relational DBMS
No two tuples are the same. No two attributes are the same. Order of tuples are immaterial. Order of attributes are immaterial. Value of attributes must be atomic.
![Page 7: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/7.jpg)
7
Relational Database Example:
StudentsCoursesFaculty
![Page 8: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/8.jpg)
Attributes of a Relation:
Students (Name, ID, Major, Minor,….)
Courses (C_num, Dept, Cr, Description)
Faculty (Name, ID, SSN, …..)
8
![Page 9: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/9.jpg)
Tuples:
Students (Name, ID, Major, Minor,….)
_________________________________John Smith 1111, ITEC, VARTMary Smith 2222, COSC, ITECLorry Joys 4444, ACCT, COSC
Courses (C_num, Dept, Cr, Description)
_______________________________________345 ITEC 3 Databases I445 ITEC 3 Databases II
9
![Page 10: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/10.jpg)
10
Keys: (Constraints)
A set of attributes whose values uniquely identify each entity.
Examples:Students (Name, ID, Major, Minor,….)Courses (C_num, Dept, Cr, Description)Faculty (Name, ID, SSN, …..)
![Page 11: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/11.jpg)
11
Keys: (Constraints)
Primary key:
1- Uniqueness:At any given time, no two tuples can have the same value for a given primary key.
2-Minimally:None of the attributes in primary key can be discarded without distorting the uniqueness property
3-Selection:A key selected by the Database Administrator.
![Page 12: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/12.jpg)
Primary key:
Key’s role is based on determination
If you know the value of attribute A, you can look up (determine) the value of attribute B.
ID GPA
12
![Page 13: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/13.jpg)
13
Keys Composite key
Composed of more than one attribute. Key attribute
Any attribute that is part of a key. Superkey
Any combination of attributes that uniquely identifies each row.
Candidate key
![Page 14: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/14.jpg)
14
Keys: (Constraints)
Foreign key:An attribute(s) in an entity set
(relation) which is the primary key of other entity set (relation)
Example: Department(Name, Dept_Id, ….) Faculty(Name, Id, Dept_Id,…)
![Page 15: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/15.jpg)
15
Normal Forms (Guidelines for RD design)
How do we know this is a good design?
If it is not a good design, What should we do?
Modify our design ??.
![Page 16: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/16.jpg)
Normalization: Process for evaluating and correcting
table structures to minimize data redundancies
Reduces data anomalies Works through a series of stages
called normal forms: First normal form (1NF) Second normal form (2NF) Third normal form (3NF)
16
![Page 17: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/17.jpg)
Why Normalize Tables: Structure of data does not handle
data very well The table structure appears to
work; Report generated with ease Unfortunately, report may yield
different results depending on what data anomaly has occurred
17
![Page 18: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/18.jpg)
Each table represents a single subject
No data item will be unnecessarily stored in more than one table
All attributes in a table are dependent on the primary key
18
![Page 19: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/19.jpg)
19
Normal Forms (Guidelines for RD design)
A relation is in 1NF if the values of domain is atomic for each attribute.
![Page 20: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/20.jpg)
20
First Normal Form: 1NF
Example: Person (Name Age Children )
Smith 42 John, Lori, Mark
Person (Name Age Children )Smith 42 JohnSmith 42 LoriSmith 42 Mark
![Page 21: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/21.jpg)
21
First Normal Form: 1NF
Example: Student ( Name Birthday )
S1 Feb 2,91S2 March 8,88
Student (Name, D_Birth, M_Birth, Y_Birth)
Note: 2NF and 3NF Deal with the relationship between non-key and key
![Page 22: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/22.jpg)
First Normal Form: Repeating group
Derives its name from the fact that a group of multiple entries of same type can exist for any single key attribute occurrence
Relational table must not contain repeating groups
Normalizing table structure will reduce data redundancies
22
![Page 23: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/23.jpg)
23
Second Normal Form: 2NF
A relation is in 2NF if it is in 1NF and every attribute is Fully dependent on the entire key in this relation.
![Page 24: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/24.jpg)
24
Second Normal Form: 2NF
Example: R(A,B,C,D)
D partially depends on A,B C fully depends on A,B A&B are prime (part of key)
If A is primary key. Is this in 2NF? If A&B is primary key. Is this in 2NF?
A, B ---> C, DA ---> D
![Page 25: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/25.jpg)
25
Second Normal Form: 2NF What should we do with a relation which
is not in 2NF?
Example: R(A,B,C,D) A, B ---> C, D A ---> D
R1 (A,B,C) R2(A,D)
![Page 26: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/26.jpg)
26
Second Normal Form: 2NF Example: R(Part Warehouse Address Quantity
P1 W1 Frostburg 25
P2 W1 Frostburg 30
P3 W2 Cumberland
32
P4 W4 Frostburg 25
P4 W1What is the primary key?
Part, Warehouse ---> QuantityWarehouse ---> Address
![Page 27: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/27.jpg)
27
Second Normal Form: 2NF
Problems:1. Repetition of information:
Changing the address W!
2. Unable to present information:Warehouse with no part
So …R1 (Warehouse, Address)R2 (Part, Warehouse, Quantity)
![Page 28: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/28.jpg)
28
Second Normal Form: 2NF
Example:
R( Professor,
Student,
Course,
Degree )
P1 S1 C1 Ph.D.
P2 S2 C2 M.S.
P3 S2 C4 M.S.
P4 S3 C4 Ph.D.Professor ---> CourseStudent ---> DegreeProfessor ---> Student
Key? Not in 2NF
R1(Student, Degree)R2(Professor, Course, Student)
![Page 29: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/29.jpg)
29
A relation is 3NF if it is in 2NF and every non-key attribute non transitively depends on the Primary Key.
Example: R(A,B,C,D) A, B --->D D ---> C
Fact: 3NF is violated when a non-key is a fact about another non-key
Third Normal Form (3NF):
R1(A,B,D)R2(D,C)
![Page 30: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/30.jpg)
30
Third Normal Form (3NF): Example: R(Employee, Dept, Location) Employee ---> Dept
Dept ---> Location
Employee Dept LocationE1 D1 Frostburg
E2 D2 Frostburg
E3 D3 Frostburg
Problems? R1(Employee, Dept)R2(Dept, Location)
![Page 31: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/31.jpg)
31
Third Normal Form (3NF): Example: R(A,B,C,D)
A,B ---> C A,C ---> D
So A,B is the Primary Key Not in 3NF
R1(A,B,C) R2(A,C,D)
![Page 32: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/32.jpg)
32
Null Values:
No data entry Not permitted in primary key It is represent as:
An unknown attribute value A known, but missing, attribute value A “not applicable” condition
![Page 33: Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649f4d5503460f94c6e443/html5/thumbnails/33.jpg)
33
Controlled redundancy: Makes the relational database work Tables within the database share
common attributes that enable the tables to be linked together
Multiple occurrences of values in a table are not redundant when they are required to make the relationship work
Redundancy exists only when there is unnecessary duplication of attribute values