1 / 67

Chapter 3 The Relational Database Model

Chapter 3 The Relational Database Model. Logical View of Data. Relational Database Designer focuses on logical representation rather than physical Use of table advantageous Structural and data independence Related records stored in independent tables Logical simplicity.

Download Presentation

Chapter 3 The Relational Database Model

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 3 The Relational Database Model

  2. Logical View of Data • Relational Database • Designer focuses on logical representation rather than physical • Use of table advantageous • Structural and data independence • Related records stored in independent tables • Logical simplicity

  3. A Logical View of Data • Relational database model’s structural and data independence • allow us to ignore the structure’s physical complexity. • enables us to view data logically rather than physically. • The logical view allows a simpler file concept of data storage. • The use of logicallyindependent tables is easier to understand. • Logical simplicity yields simpler and more effective database design methodologies.

  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 • Each entity has certain characteristics known as attributes. • Student -- Student Number, Name, GPA, Date of Enrollment, Data of Birth, Home Address, Phone Number, Major • 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.

  5. Table Characteristics • Two-dimensional structure with rows and columns • Row (tuple) represent a single entity occurrence within the entity set. • Columns represent attributes • Row/column intersection represents single value • Column values all have same data format • Each column has range of values called attribute domain • Order of the rows and columns is immaterial to the DBMS • Tables must have an attribute to uniquely identify each row

  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. entity set ≒ table ≒ relation

  7. Keys • A key Consists of one or more attributes that determineother attributes • Primary key (PK) is an attribute (or a combination of attributes) that uniquely identifies any given entity (row)

  8. Keys • 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 Aif A determines B. ( A → 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). (A is minimal !)

  9. Freshman Sophomore Junior Senior STU_HRS → STU_CLASS

  10. Keys • Superkey • Uniquely identifies each entity • Candidate key • Minimal superkey • Primary key • Candidate key selected to uniquely identify all other attributes in a given row • Secondary key • Used only for data retrieval • Foreign key • Values must match primary key in another table

  11. Super key • STU_NUM • (STU_NUM, STU_LNAME) • Candidate key • STU_NUM • (STU_LNAME, STU_FNAME, STU_INIT, STU_PHONE) • Primary key • STU_NUM • Secondary keynot necessarily yield a unique outcome • CUSTOMER table: • Primary key : Customer number • Secondary key : Customer last name, Customer phone number • A secondary key’s effectiveness in narrowing down a searchdepends on how restrictive it is.

  12. 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 (COUNT, AVERAGE, and SUM)

  13. Keys • Controlledredundancy(shared common attributes) makes the relational database work. • The primary key of one table appears again as the link (foreign key) in another table. • VEND_CODE in PRODUCT table (Figure 3.2) • referential integrity :if the foreign key contains a value, that value refers to an existing valid tuple in another relation.

  14. Integrity Rules • Entity integrity • (unique and no null)All Primary key entries are unique , and no part of a Primary key may be null . • CUS_CODE • AGENT_CODE • Referential integrity • (null or matching)A Foreign key may have either a null entry or an entry that matches the primary key value in a tableto which it is related. • AGENT_CODE

  15. null or matching

  16. Relational Database Operators • Relational algebra defines the theoretical way of manipulating table contents using the eight relational functions: • SELECT • PROJECT • JOIN • INTERSECT • UNION • DIFFERENCE • PRODUCT • DIVIDE • Use of relational algebra operators on existing tables (relations) produces new relations

  17. Relational Database Operators • UNIONcombines all rows from two tables. The two tables must be union compatible.(share the same columns and domains)

  18. INTERSECTproduces a listing that contains only the rows that appear in both tables. The two tables must be union compatible.

  19. DIFFERENCEyields all rows in one table that are not found in the other table; i.e., it subtracts one table from the other. The tables must be union compatible.

  20. PRODUCT produces a list of all possiblepairs of rows from two tables. (Cartesian product)

  21. Figure 2.9 • SELECTyields values for all rows found in a table. It yields a horizontal subset of a table.

  22. PROJECTproduces a list of all values for selected attributes. It yields a vertical subset of a table.

  23. JOINallows us to combine information from two or more tables. JOIN is the real power behind the relational database, allowing the use ofindependent tables linked by common attributes.

  24. 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 3-stage process: • A PRODUCT of the tables is created. (Figure 3.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 3.13)Common column(s) are called join column(s) • A PROJECT is performed to yield a single copy of each attribute, thereby eliminating the duplicate column. (Figure 3.14)

  25. Relational Database Operators • EquiJOINlinks tables based on an equality condition that compares specified columns of each table. The outcome of the EquiJOIN does not eliminate duplicate columns and the condition or criteria to join the tables must be explicitly defined. • Theta JOIN is an equiJOIN that compares specified columns of each table using a comparison operatorother than the equality(=) comparison operator. • In an Outer JOIN, the unmatched pairs would be retained and the values for the unmatched other tables would be left null.

  26. equiJOIN criteria(C=E)

  27. theta JOIN criteria(C<E)

  28. CUSTOMERFull Outer JOINCUSTOMER.AGENT_CODE=AGENT.AGENT_CODEAGENT

  29. CUSTOMERLeft Outer JOINCUSTOMER.AGENT_CODE=AGENT.AGENT_CODEAGENT

  30. CUSTOMERRight Outer JOINCUSTOMER.AGENT_CODE=AGENT.AGENT_CODEAGENT

  31. DIVIDErequires the use of one single-column table and one two-column table.

  32. This is not an uncommon situation, but the solution is not straightforward since the SQL SELECT statement does not directly support relational division. • There are numerous ways to achieve the same results as a relational division, however. The easiest method is to rephrase the request. Instead of "list the suppliers who provide all product categories,“ which is difficult to process, try "list all suppliers where the count of their product categories is equal to the count of all product categories."

  33. The Data Dictionary and the System Catalog • Data dictionarycontains metadata to provide detailed accounting of all tables within the database. • System catalogis a very detailed system data dictionary that describes all objects within the database. • Authorized users, access privileges … • System catalog is a system-created database whose tables store the database characteristics and contents. • Terms “system catalog” and “data dictionary” are often used interchangeably

  34. 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. • “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

  35. The 1:1 Relationship • 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

  36. The 1:1 Relationship Between PROFESSOR and DEPARTMENT

  37. The Implemented 1:1 Relationship Between PROFESSOR and DEPARTMENT

  38. The 1:M Relationship Between PAINTER and PAINTING

  39. Example 1:M Relationship

  40. The Implemented 1:M Relationship Between PAINTER and PAINTING PAINTER(PAINTER_NUM) PAINTING(PAINTING_NUM) (PAINTER_NUM)

  41. The 1:M Relationship Between COURSE and CLASS

More Related