Download presentation
Presentation is loading. Please wait.
Published byYuliana Iskandar Modified over 5 years ago
1
DCT 2053 DATABASE CONCEPT Chapter 2.2 CONTINUE
The Relational Database Model
2
A Logical View of Data Relational database model’s structural and data independence enables us to view data logically rather than physically. The logical view allows a simpler file concept of data storage. The use of logically independent tables is easier to understand. Logical simplicity yields simpler and more effective database design methodologies. Nur Sukinah Aziz TATiUC
3
A Logical View of Data Relational database model’s structural and data independence enables us to view data logically rather than physically. The logical view allows a simpler file concept of data storage. The use of logically independent tables is easier to understand. Logical simplicity yields simpler and more effective database design methodologies. Nur Sukinah Aziz TATiUC
4
A Logical View of Data Entities and Attributes
An entity is a person, place, event, or thing for which we intend to collect data. University -- Students, Faculty Members, Courses Airlines -- Pilots, Aircraft, Routes, Suppliers Each entity has certain characteristics known as attributes. Student -- Student Number, Name, GPA, Date of Enrollment, Data of Birth, Home Address, Phone Number, Major Aircraft -- Aircraft Number, Date of Last Maintenance, Total Hours Flown, Hours Flown since Last Maintenance Nur Sukinah Aziz TATiUC
5
A Logical View of Data Entities and Attributes
A grouping of related entities becomes an entity set. The STUDENT entity set contains all student entities. The FACULTY entity set contains all faculty entities. The AIRCRAFT entity set contains all aircraft entities. Nur Sukinah Aziz TATiUC
6
A Logical View of Data Tables and Their Characteristics
A table contains a group of related entities -- i.e. an entity set. The terms entity set and table are often used interchangeably. A table is also called a relation. Nur Sukinah Aziz TATiUC
7
Summary of the Characteristics
of a Relational Table Nur Sukinah Aziz TATiUC
8
STUDENT Table Attribute Values
Nur Sukinah Aziz TATiUC
9
KEY Consists of one or more attributes that determine other attributes
Primary key (PK) is an attribute (or a combination of attributes) that uniquely identifies any given entity (row) The primary key of one table appears again as the link (foreign key) in another table. If the foreign key contains either matching values or nulls, the table(s) that make use of such a foreign key are said to exhibit referential integrity. Nur Sukinah Aziz TATiUC
10
Nur Sukinah Aziz TATiUC
11
Nur Sukinah Aziz TATiUC
12
KEY A key helps define entity relationships.
The key’s role is based on a concept known as determination, which is used in the definition of functional dependence. The attribute B is functionally dependent on A if A determines B. An attribute that is part of a key is known as a key attribute. A multi-attribute key is known as a composite key. If the attribute (B) is functionally dependent on a composite key (A) but not on any subset of that composite key, the attribute (B) is fully functionally dependent on (A). Nur Sukinah Aziz TATiUC
13
Relational Database Keys
Nur Sukinah Aziz TATiUC
14
Integrity Rules Revisited
Nur Sukinah Aziz TATiUC
15
NULL Values No data entry Not permitted in primary key
Should be avoided in other attributes Can represent An unknown attribute value A known, but missing, attribute value A “not applicable” condition Can create problems in logic and using formulas Nur Sukinah Aziz TATiUC
16
Controlled Redundancy
Makes the relational database work Tables within the database share common attributes that enable us to link tables together Multiple occurrences of values in a table are not redundant when they are required to make the relationship work Redundancy is unnecessary duplication of data Nur Sukinah Aziz TATiUC
17
Relational Database Operators
Relational algebra Defines theoretical way of manipulating table contents using relational operators: SELECT PROJECT JOIN INTERSECT Use of relational algebra operators on existing tables (relations) produces new relations UNION DIFFERENCE PRODUCT DIVIDE Nur Sukinah Aziz TATiUC
18
Relational Database Operators(cont’d)
Union: Combines all rows from two tables, excluding duplicate rows Tables must have the same attribute characteristics Intersect: Yields only the rows that appear in both tables Nur Sukinah Aziz TATiUC
19
Union Nur Sukinah Aziz TATiUC
20
Intersect Nur Sukinah Aziz TATiUC
21
Relational Database Operators(cont’d)
Difference Yields all rows in one table not found in the other table—that is, it subtracts one table from the other Product Yields all possible pairs of rows from two tables Also known as the Cartesian product Nur Sukinah Aziz TATiUC
22
Difference Nur Sukinah Aziz TATiUC
23
Difference Nur Sukinah Aziz TATiUC
24
Relational Database Operators(cont’d)
Select Yields values for all rows found in a table Can be used to list either all row values or it can yield only those row values that match a specified criterion Yields a horizontal subset of a table Project Yields all values for selected attributes Yields a vertical subset of a table Nur Sukinah Aziz TATiUC
25
Select Nur Sukinah Aziz TATiUC
26
Project Nur Sukinah Aziz TATiUC
27
Relational Database Operators(cont’d)
Join Allows us to combine information from two or more tables Real power behind the relational database, allowing the use of independent tables linked by common attributes Nur Sukinah Aziz TATiUC
28
Nur Sukinah Aziz TATiUC
29
Natural Join Links tables by selecting only rows with common values in their common attribute(s) Result of a three-stage process: PRODUCT of the tables is created SELECT is performed on Step 1 output to yield only the rows for which the AGENT_CODE values are equal Common column(s) are called join column(s) PROJECT is performed on Step 2 results to yield a single copy of each attribute, thereby eliminating duplicate columns Nur Sukinah Aziz TATiUC
30
Nur Sukinah Aziz TATiUC
31
Nur Sukinah Aziz TATiUC
32
Natural Join (cont’d) Final outcome yields table that
Does not include unmatched pairs Provides only copies of matches If no match is made between the table rows, the new table does not include the unmatched row Nur Sukinah Aziz TATiUC
33
Other Forms of Join Equijoin
Links tables on the basis of an equality condition that compares specified columns of each table Outcome does not eliminate duplicate columns Condition or criterion to join tables must be explicitly defined Takes its name from the equality comparison operator (=) used in the condition Nur Sukinah Aziz TATiUC
34
Other Forms of Join Theta join
is an equiJOIN that compares specified columns of each table using a comparison operator other than the equality comparison operator. Nur Sukinah Aziz TATiUC
35
Outer Join Matched pairs are retained and any unmatched values in other table are left null In outer join for tables CUSTOMER and AGENT, two scenarios are possible: Left outer join Yields all rows in CUSTOMER table, including those that do not have a matching value in the AGENT table Right outer join Yields all rows in AGENT table, including those that do not have matching values in the CUSTOMER table Nur Sukinah Aziz TATiUC
36
Nur Sukinah Aziz TATiUC
37
Nur Sukinah Aziz TATiUC
38
Divide DIVIDE requires the use of one single-column table and one two-column table Nur Sukinah Aziz TATiUC
39
The Data Dictionary and the System Catalog
Used to provide detailed accounting of all tables found within the user/designer-created database Contains (at least) all the attribute names and characteristics for each table in the system Contains metadata—data about data Sometimes described as “the database designer’s database” because it records the design decisions about tables and their structures Nur Sukinah Aziz TATiUC
40
Nur Sukinah Aziz TATiUC
41
The Data Dictionary and the System Catalog
System catalog is a very detailed system data dictionary that describes all objects within the database. System catalog is a system-created database whose tables store the database characteristics and contents. System catalog tables can be queried just like any other tables. System catalog automatically produces database documentation. Nur Sukinah Aziz TATiUC
42
Relationships within the Relational Database
E-R Diagram (ERD) Rectangles are used to represent entities. Entity names are nouns and capitalized. Diamonds are used to represent the relationship(s) between the entities. The number 1 is used to represent the “1” side of the relationship. The letter M is used to represent the “many” sides of the relationship. Nur Sukinah Aziz TATiUC
43
Relationships within the Relational Database(cont’d)
Three Types of Relationships: One-to-many relationships (1:M) Relational modeling ideal Should be the norm in any relational database design A painter paints many different paintings, but each one of them is painted by only that painter. PAINTER (1) paints PAINTING (M) Many-to-many relationships (M:N) Must be avoided because they lead to data redundancies An employee might learn many job skills, and each job skill might be learned by many employees. EMPLOYEE (M) learns SKILL (N) Nur Sukinah Aziz TATiUC
44
Relationships within the Relational Database(cont’d)
One-to-one relationships (1:1) Should be rare in any relational database design Each store is managed by a single employee and each store manager (employee) only manages a single store. EMPLOYEE (1) manages STORE (1) Nur Sukinah Aziz TATiUC
45
The 1:1 Relationship Relational database norm
Found in any database environment One entity can be related to only one other entity, and vice versa Often means that entity components were not defined properly Could indicate that two entities actually belong in the same table Sometimes 1:1 relationships are appropriate Nur Sukinah Aziz TATiUC
46
The 1:1 Relationship Between PROFESSOR and DEPARTMENT
Nur Sukinah Aziz TATiUC
47
Nur Sukinah Aziz TATiUC
48
Nur Sukinah Aziz TATiUC
49
Nur Sukinah Aziz TATiUC
50
Nur Sukinah Aziz TATiUC
51
Nur Sukinah Aziz TATiUC
52
Nur Sukinah Aziz TATiUC
53
The M:N Relationship Can be implemented by breaking it up to produce a set of 1:M relationships Can avoid problems inherent to M:N relationship by creating a composite entity or bridge entity Nur Sukinah Aziz TATiUC
54
Nur Sukinah Aziz TATiUC
55
Nur Sukinah Aziz TATiUC
56
Linking Table Implementation of a composite entity
Yields required M:N to 1:M conversion Composite entity table must contain at least the primary keys of original tables Linking table contains multiple occurrences of the foreign key values Additional attributes may be assigned as needed Nur Sukinah Aziz TATiUC
57
Nur Sukinah Aziz TATiUC
58
Nur Sukinah Aziz TATiUC
59
Nur Sukinah Aziz TATiUC
60
Nur Sukinah Aziz TATiUC
61
Data Redundancy Revisited
Data redundancy leads to data anomalies Such anomalies can destroy database effectiveness Foreign keys Control data redundancies by using common attributes shared by tables Crucial to exercising data redundancy control Sometimes, data redundancy is necessary Nur Sukinah Aziz TATiUC
62
Nur Sukinah Aziz TATiUC
63
Nur Sukinah Aziz TATiUC
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.