430 likes | 644 Views
Chapter 2. The Relational Database Model Database Systems: Design, Implementation, and Management, Fifth Edition, Rob and Coronel. TOPICS. ENTITIES & ATTRIBUTES TABLES KEYS INTEGRITY RULES RELATIONAL ALGEBRA DATA DICTIONARY CONTROLLED REDUNDANCY INDEXING. Database Design.
E N D
Chapter 2 The Relational Database Model Database Systems: Design, Implementation, and Management, Fifth Edition, Rob and Coronel
TOPICS • ENTITIES & ATTRIBUTES • TABLES • KEYS • INTEGRITY RULES • RELATIONAL ALGEBRA • DATA DICTIONARY • CONTROLLED REDUNDANCY • INDEXING
Database Design • Determine Entities • Identify each entities characteristics (attributes) • Name attributes • Assign data types and size • Determine constraints and domain • Identify candidate keys • Assign Primary key • Assign secondary (alternate) keys
Logical View of Data • Relational Database • Designer focuses on logical (what) representation rather than physical (how) • Use of table advantageous • Structural and data independence • Related records stored in independent tables • Logical simplicity • Allows for more effective design strategies
Logical View of Data (con’t.) • Entities and Attributes • Entity is a person, place, event, or thing about which data is collected • Entity names are SINGULAR NOUNS • Attributes are characteristics of the entity • Tables • Holds related entities or entity set • Also called relations • Comprised of rows and columns
Summary of the Characteristics of a Relational Table Table 2.1
Example Tables Figure 2.1
Keys • Controlled redundancy (shared common attributes) makes the relational database work. • The primary key is an attribute that uniquely identifies any given entity(row). • To have entity integrity, a table must have a primary key and must not have a null value in the primary key.
Keys • The primary key of one table appears again as the link (foreign key) in another table • This is where controlled redundancy comes into place. • 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
Keys • 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).
Relational Database Operators • The degree of relational completeness can be defined by the extent to which relational algebra is supported. • Relational algebra defines the theoretical way of manipulating table contents using the eight relational functions: SELECT, PROJECT, JOIN, INTERSECT, UNION, DIFFERENCE, PRODUCT, and DIVIDE.
Union Combines all rows Figure 2.5
Intersect Yields rows that appear in both tables Figure 2.6
Difference Yields rows not found in other tables Figure 2.7
Product Yields all possible pairs from two tables
Divide Requires use of single-column table and two-column table Figure 2.17
Select Yields a subset of rows based on specified criterion
Project Yields all values for selected attributes (columns)
Join Information from two or more tables is combined Figure 2.11 Figure 2.14
Relational Database Operators • Natural JOIN links tables by selecting only the rows with common values in their common attribute(s). It is the result of a three-stage process: • A PRODUCT of the tables is created. (Figure 2.12) • A SELECT is performed on the output of the first step to yield only the rows for which the common attribute values match. (Figure 2.13) • A PROJECT is performed to yield a single copy of each attribute, thereby eliminating the duplicate column. (Figure 2.14)
Natural Join, Step 1: PRODUCT Figure 2.12
Figure 2.13 Natural Join, Step 2: SELECT Figure 2.14 Natural Join, Step 3: PROJECT
Join • Natural join: EquiJoin with the duplicate column removed. Performed by a Project on the result of equijoin. (aka Inner Join) • When the term Join is mentioned without any prefix, it is implied to be Natural Join. • Outer Join: Unmatched rows from the participating tables are retained in the result table with unmatched attributes left blank or null. • Left Outer join keeps all tuples from the left relation • Right Outer Join keeps all tuples from the right relation • Theta Join: EquiJoin with the equality operator replaced by any other comparison operator, such as greater than, less than, etc.
Data Dictionary and System Catalog • Data dictionary • Provides detailed account of all tables found within database • Metadata • Attribute names and characteristics • System catalog • Detailed data dictionary • System-created database • Stores database characteristics and contents • Tables can be queried just like any other tables • Automatically produces database documentation
Relationships within Relational Database • Relationship classifications • 1:1 • 1:M • M:N • E-R Model • ERD Maps E-R model • Chen • Crow’s Feet
ERD Symbols • Rectangles represent entities • Diamonds represent the relationship(s) between the entities • “1” side of relationship • Number 1 in Chen Model • Bar crossing line in Crow’s Feet Model • “Many” relationships • Letter “M” and “N” in Chen Model • Three pronged “Crow’s foot” in Crow’s Feet Model
Example 1:M Relationship Figure 2.18
Example M:N Relationship Figure 2.24
Converting M:N Relationship to Two 1:M Relationships Figure 2.25
Converting M:N Relationship to Two 1:M Relationships (con’t.) Figure 2.26
Converting M:N Relationship to Two 1:M Relationships (con’t.) Figure 2.27
Converting M:N Relationship to Two 1:M Relationships (con’t.) Figure 2.28
Data Redundancy Revisited • Foreign keys can reduce redundancy • Some redundancy is desirable • Called controlled redundancy • Speed • Information requirements
Indexes • Points to location • Makes retrieval of data faster Figure 2.31