The relational database model chapter 2
-
Upload
sonabir -
Category
Data & Analytics
-
view
201 -
download
0
description
Transcript of The relational database model chapter 2
![Page 1: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/1.jpg)
Chapter 2
The Relational Database Model
![Page 2: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/2.jpg)
2
Logical View of DataRelational Database
Designer focuses on logical representation rather than physicalUse of table advantageous
Structural and data independenceRelated records stored in independent tablesLogical simplicity
Allows for more effective design strategies
![Page 3: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/3.jpg)
3
Logical View of Data (con’t.)
Entities and Attributes Entity is a person, place, event, or thing about which data is collectedAttributes are characteristics of the entity
TablesHolds related entities or entity setAlso called relationsComprised of rows and columns
![Page 4: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/4.jpg)
4
Table Characteristics• Two-dimensional structure with rows and
columns• Rows (tuples) represent single entity• Columns represent attributes• Row/column intersection represents single
value• Tables must have an attribute to uniquely
identify each rowPrimary key: attribute and a combination of combined attributes that uniquely identify any given entity (row)
![Page 5: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/5.jpg)
5
Table Characteristics (con’t.)
• Column values all have same data format
Data types: Number Character Date Logical
• Each column has range of values called attribute domain
• Order of the rows and columns is immaterial to the DBMS
![Page 6: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/6.jpg)
6
Rowentity
Column (attribute)Entity set value
![Page 7: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/7.jpg)
7
![Page 8: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/8.jpg)
8
Integrity RulesEntity integrity
Requirement (Ensures all entities are unique): all primary key entries are unique; no null valueEach entity has unique key
Referential integrityForeign key must match primary key valuesMakes it impossible to delete row whose primary key has mandatory matching foreign key values in another table
![Page 9: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/9.jpg)
9
Relational Database Operators
Relational algebra defines the theoretical way of manipulating table contents using the eight relational operators, or relational algebra determines table manipulationsKey operators
SELECTPROJECTJOIN
![Page 10: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/10.jpg)
10
Relational Database Operators
Other operatorsINTERSECTUNIONDIFFERENCEPRODUCTDIVIDE
![Page 11: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/11.jpg)
11
UNION
Tables must have the same attribute characters (column and domains must be identical)
That is called these tables are UNION compatible
Combines all rows Example:
![Page 12: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/12.jpg)
12
Union
Figure 2.5
![Page 13: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/13.jpg)
13
Intersect
Tables must be UNION compatible
Yield rows appear in both tables
Example:
![Page 14: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/14.jpg)
14
Yields rows that appear in both tables
Intersect
Figure 2.6
![Page 15: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/15.jpg)
15
Difference
Tables must be UNION compatible
Find rows in table that are not found in the other table.
Example:
![Page 16: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/16.jpg)
16
Yields rows not found in other tables
Difference
Figure 2.7
![Page 17: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/17.jpg)
17
Product
Yields all possible pairs of rows from two tables
Example:
![Page 18: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/18.jpg)
18
Product
Figure 2.8
![Page 19: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/19.jpg)
19
Select Yields values for all rows
found in a table. Select can be used to either
list all or list partial rows values that match a specified criterion.
Example:
![Page 20: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/20.jpg)
20
Select
![Page 21: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/21.jpg)
21
Project
Project yields a vertical subset of a table with selected attributes
Example:
![Page 22: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/22.jpg)
22
Project
Figure 2.10
![Page 23: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/23.jpg)
23
Join Combine information from
multiple tables Natural join process
Product Select Project
Example:
![Page 24: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/24.jpg)
24
Join
Figure 2.11
Figure 2.14
![Page 25: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/25.jpg)
25
Links tables by selecting rows with common values in common attribute(s)Three-stage process
Product creates one tableSelect yields appropriate rowsProject yields single copy of each attribute to eliminate duplicate columns
Natural Join Process
![Page 26: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/26.jpg)
26
Product Process in Join
![Page 27: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/27.jpg)
27
![Page 28: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/28.jpg)
28
Select Process in Join
![Page 29: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/29.jpg)
29
Project Process in Join
![Page 30: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/30.jpg)
30
Other Joins
EquiJOINLinks tables based on equality condition that compares specified columns of tables Does not eliminate duplicate columns Join criteria must be explicitly defined
![Page 31: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/31.jpg)
31
Other Joins
EquiJOIN that compares specified columns of each table using operator other than equality one
Theta JOINAny other comparison operator is used, it is generally called a theta JOIN
![Page 32: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/32.jpg)
32
Other JoinsOuter JOIN
Matched pairs are retained Unmatched values in other tables left nullRight and left outer JOINExample:
![Page 33: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/33.jpg)
33
![Page 34: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/34.jpg)
34
![Page 35: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/35.jpg)
35
Divide
Use of one single-column table and one two-column table
Find the values associate with A and B Table
Example:
![Page 36: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/36.jpg)
36
Requires user of single-column table and two-column table
Divide
Figure 2.17
![Page 37: The relational database model chapter 2](https://reader033.fdocuments.net/reader033/viewer/2022061209/548c509cb479591d7f8b45d5/html5/thumbnails/37.jpg)
37
Data Dictionary and System Catalog
Data dictionaryProvides detailed account of all tables found within databaseMetadataAttribute names and characteristicsAll members of database design and implementation teams use the same table, attributes and characteristicsDBMS internally store data dictionary and additional information containing relationship types, entity and
referential integrity check and enforcement. Database designer’s database
System catalogDetailed data dictionary; current relational database software provides only a system catalogData dictionary can be derived fromStores database characteristics and contents