Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational Database. I. Relational Database 1. Introduction 2. Database Models 3. Relational Database 4. Entity-Relationship Models 5. RDB Design Principles.

Similar presentations


Presentation on theme: "Relational Database. I. Relational Database 1. Introduction 2. Database Models 3. Relational Database 4. Entity-Relationship Models 5. RDB Design Principles."— Presentation transcript:

1 Relational Database

2 I. Relational Database 1. Introduction 2. Database Models 3. Relational Database 4. Entity-Relationship Models 5. RDB Design Principles

3 1. Introduction Database Is a collection of related data Is persistent Database Management System Software system to add, delete, search, and modify the data in the DB To provide various ways to view the data in the DB

4 2. Database Models Flat Database Hierarchical DB Network DB Relational DB

5 Flat Database Flat Database (Library DB) Redundancy Publisher name is repeated Publisher phone number is repeated Author phone is repeated If publisher address is included, … ? Update Anomalies To modify publisher phone, all need to be modified

6 Insertion Anomaly A new publisher, with no data about book, author, and other details which are not available, cannot be included. Deletion Anomaly If a book is deleted, its publisher data, or author data, can also be eliminated (e.g., last book in the list)

7 Solution Break up Flat-file DB into Separe Tables TablesTables (Library DB)

8 Hierarchical DB Model Agents Agency Database PaymentsEngagements Schedules Entertainers Clients (This and remaining slides on DB Models are adapted from Database Design for Mere Mortals, Michael Hernandez, Addison Wesley, 1999) Back to Ref Ing

9 Hierarchical DBM Characteristics One table acts as a root of an inverted tree; other tables are branches Each child table may have only one parent table Each parent table may have many child tables To access any data, must start at root table

10 Hierarchical DBM Advantages & Disadvantages Advantages: Data retrieve is fast, because table structure is explicitly linked Data retrieve is fast, because table structure is explicitly linked Referential integrity is built in Disadvantages: Difficult to store data in child table when no corresponding record exists in parent tables. E.g., a new entertainer cannot be entered in the DB until a specific Agent is assigned Difficult to store data in child table when no corresponding record exists in parent tables. E.g., a new entertainer cannot be entered in the DB until a specific Agent is assigned Difficult to model complex relationships Difficult to add new tables

11 Referential Integrity Each record in a child table is linked to an existing record in the parent table. E.g., every Payment record is associated with a particular Client.E.g., every Payment record is associated with a particular Client. If a record is deleted in a parent table,all associated record in child tables are also deleted. E.g., If a particular Client record is deleted, all related records in Payments and Engagements are deleted—no orphans.E.g., If a particular Client record is deleted, all related records in Payments and Engagements are deleted—no orphans.

12 Network Database Model Agents Agency Database Musical StylesEngagementsPayments Clients Entertainers representsmanages performs schedulesmakesplays

13 Network DBM Characteristics Invented to address problems with the Hierarchical DB Model A child table can have more than one parent table Can go up or down the structure. E.g., to answer “Who was the agent that booked a particular engagement?”, start with Engagements, Clients, then to Agents.

14 Relational Database Collection of tables e.g., books, authors, publishers, clients Each cell in a table is atomic i.e., no formulas, pointers, but single data item Tables are linked by common values in selected columns i.e., not by pointers Books Table Publishers Table

15 Basic Terminology Data & Information These are data values Kashimata 25 October 31 25000 This is information Customer’s last Name: Kashimata Age: 25 Birthday: October 31 Savings Account Balance: $25,000

16 Basic Terminology Null Null, zero, and blank Age = Null age is undefined Age = 0 age is 0 MiddleName = Null middle name is undefined MiddleName = “” person has no middle name MiddleName = “ “ no middle name, takes up 1 byte

17 Basic Terminology Table, Record, Field

18 Basic Terminology Table Table (Books Table)(Books Table) Represents an entity (category) of objects with its (relevant) attributes Consists of rows (records) and columns (fields) In the Books table, each record is an instance of the Books category. Each field represents an attribute

19 Basic Terminology Attributes (fields) To provide specific information about entity To help identify individual entities--e.g., ISBN for books, SSN for employee, Sales_ID for sales. To describe relationship between entity entities in different entity classes For example...

20 Your Turn. Identify Attributes.. Entity Classes for School Database Students Faculty Staff Buildings Rooms Course Class

21 Identify Attributes... Entity Classes For a Bank Database Customers Account Employee Transaction

22 Basic Terminology Keys Superkey Set of attributes to identify a record uniquely in a set--e.g., to distinguish one book from all others. ISBN, ISBN+TITLE, ISBN+TITLE+AUTHOR Key or Candidate Key Minumum superkey. E.g., ISBN Primary Key A Key that is chosen for a particular table

23 Primary Key Employee Class FirstName LastName SSN PhoneNumber DateOfBirth E-mail Candidate Key SSN FirstName +LastName + DateOfBirth E-mail? E-mail + DateOfBirth Primary Key SSN

24 Types of Relationships (Library DB) How are the tables associated with each other, so that information can be extracted from multiple tables? Publishers Authors Books

25 Types of Relationships 1 to many (most common) A publisher may publish many books, but each book may have only one publisher A publisher may publish many books, but each book may have only one publisher may to many (undesirable) A book may be written by many authors, and an author may write many books. A book may be written by many authors, and an author may write many books. 1 to 1 (not as common) One author has at most one secretary, and each secretary works for only one author One author has at most one secretary, and each secretary works for only one author

26 One-To-Many Relationship One record in Publishers can be related to many records in Books But, each record in Books can be associated with only one record in Publishers PublishersBooks ∞ 1 PublishersBooks 1 1

27 Many-to-Many Relationship One record in Authors can be related to many records in Books And, each record in Books can be associated with many records in Authors AuthorsBooks ∞ 1 AuthorsBooks ∞ 1

28 One-to-One Relationship One record in Authors can be related to only one record in Secretaries And, each record in Secretaries can be associated with only record in Authors AuthorsSecretaries 1 1 Authors 1 1 Secretaries

29 Example Database Type Library Tables Books Publishers One-to-Many Relationship? Yes Why?

30 Example Database Type Order Tracking Tables Customers Orders One-to-Many Relationship? Yes Why?

31 Example Database Type School Scheduling Tables Classes Students One-to-Many Relationship? No (Many-to-Many) Why?

32 Data Integrity Table-level integrity E.g., no duplicate records (by defining a primary key) Field-level integrity E.g., do all “State” field require 2 characters? Each field contains a single atomic value? (e.g., Author field should not contain 2 authors Relationship-level integrity E.g., no many-to-many relationships Prevent “orphans.” e.g., if a publisher record is deleted, a book record is left without a publisher.


Download ppt "Relational Database. I. Relational Database 1. Introduction 2. Database Models 3. Relational Database 4. Entity-Relationship Models 5. RDB Design Principles."

Similar presentations


Ads by Google