COMP Instructor: Dimitris Papadias WWW page:

Similar documents
CSIT5300: Advanced Database Systems

Chapter 2: Entity-Relationship Model. Entity Sets. Entity Sets customer and loan. Attributes. Relationship Sets. A database can be modeled as:

Chapter 2: Entity-Relationship Model

Chapter 6: Entity-Relationship Model

Chapter 6: Entity-Relationship Model

Chapter 6: Entity-Relationship Model

Overview of db design Requirement analysis Data to be stored Applications to be built Operations (most frequent) subject to performance requirement

Design Process Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of the Bank Database Reduction to

High Level Database Models

Example: specific person, company, event, plant

Introduction to Database Design. Dr. Kanda Runapongsa Dept of Computer Engineering Khon Kaen University

High-Level Database Models (ii)

VARDHAMAN COLLEGE OF ENGINEERING Shamshabad , Hyderabad B.Tech. CSE IV Semester (VCE - R11) T P C 3+1* -- 4 (A1511) DATABASE MANAGEMENT SYSTEMS

Database Management Systems. Chapter 2 Part 2

Lecture 14 of 42. E-R Diagrams, UML Notes: PS3 Notes, E-R Design. Thursday, 15 Feb 2007

Introduction to Database Design

The Entity-Relationship Model

Entity-Relationship Modelling. Entities Attributes Relationships Mapping Cardinality Keys Reduction of an E-R Diagram to Tables

Database Applications (15-415)

The Entity-Relationship (ER) Model 2

Chapter 6: Entity-Relationship Model. E-R Diagrams

From ER to Relational Model. Book Chapter 3 (part 2 )

Data Modeling. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

A database can be modeled as: + a collection of entities, + a set of relationships among entities.

Chapter 6: Entity-Relationship Model. The Next Step: Designing DB Schema. Identifying Entities and their Attributes. The E-R Model.

The Entity-Relationship Model

Unit I. By Prof.Sushila Aghav MIT

The Entity-Relationship Model. Overview of Database Design

The Next Step: Designing DB Schema. Chapter 6: Entity-Relationship Model. The E-R Model. Identifying Entities and their Attributes.

CSE 530A. ER Model. Washington University Fall 2013

Database System Concepts

Introduction to Database Design

MIS Database Systems Entity-Relationship Model.

Database Systems. Lecture2:E-R model. Juan Huo( 霍娟 )

Database Management Systems. Chapter 3 Part 2

6.1 RELATIONSHIP CONCEPTS

Entity-Relationship Model

Intro to DB CHAPTER 6

The Entity-Relationship (ER) Model

Contents. Database. Information Policy. C03. Entity Relationship Model WKU-IP-C03 Database / Entity Relationship Model

OVERVIEW OF DATABASE DEVELOPMENT

Unit1: Introduction. Database System Concepts, 6 th Ed. Silberschatz, Korth and Sudarshan See for conditions on re-use

The Relational Model. Chapter 3. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

CIS 330: Applied Database Systems. ER to Relational Relational Algebra

CIS 330: Web-driven Web Applications. Lecture 2: Introduction to ER Modeling

Database Design. ER Model. Overview. Introduction to Database Design. UVic C SC 370. Database design can be divided in six major steps:

The Entity-Relationship Model. Overview of Database Design. ER Model Basics. (Ramakrishnan&Gehrke, Chapter 2)

The Entity-Relationship Model. Steps in Database Design

The Relational Model 2. Week 3

Overview. Introduction to Database Design. ER Model. Database Design

The Entity-Relationship Model

The Relational Model. Chapter 3

The Relational Model (ii)

Conceptual Design. The Entity-Relationship (ER) Model

Chapter 7: Entity-Relationship Model

Chapter 7: Entity-Relationship Model

Database Management System. Fundamental Database Concepts

CS/INFO 330 Entity-Relationship Modeling. Announcements. Goals of This Lecture. Mirek Riedewald

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

Introduction to Database Design

CONCEPTUAL DESIGN: ER TO RELATIONAL TO SQL

Chapter 7: Entity-Relationship Model

Chapter 1: Introduction

Introduction to Data Management. Lecture #5 (E-R Relational, Cont.)

2. E-R Model. Entity Sets Relationship Sets Attributes

The Relational Model. Outline. Why Study the Relational Model? Faloutsos SCS object-relational model

Introduction to Data Management. Lecture #6 E-Rà Relational Mapping (Cont.)

SYLLABUS ADMIN DATABASE SYSTEMS I WEEK 2 THE ENTITY-RELATIONSHIP MODEL. Assignment #2 changed. A2Q1 moved to A3Q1

Chapter 7: Entity-Relationship Model

CSCC43H: Introduction to Databases

Chapter 1: Introduction

Chapter 1: Introduction


Entity Relationship Data Model. Slides by: Shree Jaswal

UNIT I. Introduction

ER Model Overview. The Entity-Relationship Model. Database Design Process. ER Model Basics

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

The En'ty Rela'onship Model

Chapter 7: Entity-Relationship Model. Chapter 7: Entity-Relationship Model

COMP 244. ER-Diagram Notations. Entity-Relationship Diagrams DATABASE CONCEPTS & APPLICATIONS. Database Concepts & Applications 1.

Introduction to Data Management. Lecture #3 (Conceptual DB Design) Instructor: Chen Li

CS425 Fall 2016 Boris Glavic Chapter 1: Introduction

2004 John Mylopoulos. The Entity-Relationship Model John Mylopoulos. The Entity-Relationship Model John Mylopoulos

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

Database Applications (15-415)

Overview of Database Design Process Example Database Application (COMPANY) ER Model Concepts

Chapter 1: Introduction. Chapter 1: Introduction

Introduction to Data Management. Lecture #4 (E-R à Relational Design)

Chapter 1: Introduction

Relational Databases BORROWED WITH MINOR ADAPTATION FROM PROF. CHRISTOS FALOUTSOS, CMU /615

The Relational Model. Roadmap. Relational Database: Definitions. Why Study the Relational Model? Relational database: a set of relations

D.Hemavathi & R.Venkatalakshmi, Assistant Professor, SRM University, Kattankulathur

COMP 244 DATABASE CONCEPTS & APPLICATIONS

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

Relational Model. Topics. Relational Model. Why Study the Relational Model? Linda Wu (CMPT )

Database Applications (15-415)

Database Systems. Course Administration

UNIT II A. ENTITY RELATIONSHIP MODEL

Introduction to Data Management. Lecture #3 (Conceptual DB Design)

Major components of ER diagram Practices

Transcription:

COMP 5311 Instructor: Dimitris Papadias WWW page: http://www.cse.ust.hk/~dimitris/5311/5311.html Textbook Database System Concepts, A. Silberschatz, H. Korth, and S. Sudarshan. Reference Database Management Systems, Raghu Ramakrishnan and Johannes Gehrke. Grading Policy: final, presentation/survey Exams will be with open books and notes. 1

Course Outline E/R Model Relational Model, Algebra SQL Functional Dependencies and Relational Database Design File Systems Indexing Query Processing and Implementation of Relational Operators Query Optimization Transactions 2

What is a Database Management System (DBMS) Collection of interrelated data + Set of programs to access the data DBMS contains information about a particular enterprise DBMS provides an environment that is both convenient and efficient to use. Database Applications: Banking: all transactions Airlines: reservations, schedules Universities: registration, grades Sales: customers, products, purchases Manufacturing: production, inventory, orders, supply chain Human resources: employee records, salaries, tax deductions Databases touch all aspects of our lives 3

DBMS vs File Systems In the early days, database applications were built on top of file systems Drawbacks of using file systems to store data: Data redundancy and inconsistency Multiple file formats, duplication of information in different files Difficulty in accessing data Need to write a new program to carry out each new task Integrity problems Integrity constraints (e.g. account balance > 0) become part of program code Hard to add new constraints or change existing ones 4

DBMS vs File Systems (cont) Drawbacks of using file systems (cont.) Atomicity of updates Failures may leave database in an inconsistent state with partial updates carried out E.g. transfer of funds from one account to another should either complete or not happen at all Concurrent access by multiple users Concurrent accesses needed for performance Uncontrolled concurrent accesses can lead to inconsistencies E.g. two people reading a balance and updating it at the same time Security problems DBMS offer automated solutions to all the above problems; they solve problems caused by different people writing different applications independently. 5

Data Independence One big problem in application development is the separation of applications from data Do I have change my program when I replace my hard drive? store the data in a b-tree instead of a hash file? partition the data into two physical files (or merge two physical files into one)? store salary as floating point number instead of integer? develop other applications that use the same set of data? add more data fields to support other applications? Solution: introduce levels of abstraction. 6

Three Levels of Abstraction ARR CSE Dept Financial Office view 1 view 2..... view n Logical view HKUST database Physical view Files on disks 7

Three Levels of Abstraction (cont.) Physical level: describe how a record is stored on disks. e.g., Divide the customer records into 3 partitions and store them on disks 1, 2 and 3. Logical level: describes data stored in database, and the relationships among the data. Similar to defining a record type in Pascal or C: Type customer = record name: string; street: string; city: integer; end; View level: Define a subset of the database for a particular application. Views can also hide information (e.g. salary) for security purposes. 8

Data Independence Ability to modify a schema definition in one level without affecting a schema definition in the next higher level. The interfaces between the various levels and components should be well defined so that changes in some parts do not seriously influence others. Two levels of data independence: - Physical data independence (users are shielded from changes in the physical structure of the data) - Logical data independence (users are shielded from changes in the logical structure of the data) 9

Data Models A collection of tools for describing: data data relationships data semantics data constraints 10

Basic Concepts of ER ER is a model for the logical level it describes the structure of the database at a high abstraction level A database can be modeled as a collection of entities relationship among entities An entity is an object that exists independently and is distinguishable from other objects. an employee, a company, a car, a student, a class etc. color, age, etc. are not entities 11

Attributes Properties of an entity or a relationship name, address, weight, height are properties of a Person entity. date of marriage is a property of the relationship Marriage. 12

Types of Attributes Simple attribute: contains a single value. EmpNo Employee Name Address 13

Composite attribute: consists of several components (e.g., address) EmpNo Employee Address Name Street City Country 14

Multivalued attribute: contains more than one value Employee Phone Email 15

Derived attribute: computed from other attributes (e.g., age can be computed from the date of birth and the current date) Employee Age Date of birth 16

Key Attributes A set of attributes that can uniquely identify an entity ERD tabular Employee EmpNo Name EmpNo Name... 123456 John Wong... 456789 Mary Cheung... 146777... John Wong 17

Key Attributes An entity may have more than one key A minimal set of attributes that uniquely identifies an entity is called a candidate key. Question: which are possible candidate keys for HKUST students? Only one candidate key is selected to be the primary key. Question: which is the primary key for HKUST students? Sometimes artificial keys maybe created Example: assume that we want to store information about the current offering of COMP 5311. We can select a unique number (e.g., 1235) to serve as the key. Question: which are possible alternatives for this example, without introducing additional attributes? Composite Key: contains two or more attributes 18

Example Entity (Customer) 19

Relationship A relationship is an association among several entities The degree refers to the number of entity sets that participate in a relationship set. Relationship sets that involve two entity sets are binary (or degree two). Relationships among more than two entity sets are rare. (More on this later.) 20

Example of (Binary) Relationship Borrower is a relationship between Customers and Loans (it means that a customer can be associated with one or more loans and vice versa). 21

Relationship Sets with Attributes Depositor is a relationship between Customers and Accounts Access-date is an attribute of Depositor 22

Cardinality Constraints We express cardinality constraints by drawing either a directed line ( ), signifying one, or an undirected line ( ), signifying many, between the relationship set and the entity set. E.g.: One-to-one relationship: A customer is associated with at most one loan via the relationship borrower A loan is associated with at most one customer via borrower 23

One-To-Many Relationship In the one-to-many relationship a loan is associated with at most one customer via borrower, a customer is associated with several (including 0) loans via borrower 24

Many-To-One Relationships In a many-to-one relationship a loan is associated with several (including 0) customers via borrower, a customer is associated with at most one loan via borrower 25

Many-To-Many Relationship A customer is associated with several (possibly 0) loans via borrower A loan is associated with several (possibly 0) customers via borrower 26

Participation of an Entity Set in a Relationship Set Total participation (indicated by double line): every entity in the entity set participates in at least one relationship in the relationship set E.g. participation of loan in borrower is total every loan must have at least a customer associated to it via borrower Partial participation: some entities may not participate in any relationship in the relationship set E.g. participation of customer in borrower is partial some customers may not have any loans 27

Alternative Notation for Cardinality Limits Cardinality limits can also express participation constraints 28

Cardinality Limits The edge between loan and borrower has a cardinality constraint of 1..1, meaning the minimum and the maximum cardinality are both 1. each loan must have exactly one associated customer. The limit 0.. on the edge from customer to borrower indicates that a customer can have zero or more loans. Thus, the relationship borrower is one to many from customer to loan, the participation of loan in borrower is total. 29

Roles Entity sets of a relationship need not be distinct The labels manager and worker are called roles; they specify how employee entities interact via the works-for relationship set. Roles are indicated in E-R diagrams by labeling the lines that connect diamonds to rectangles. Role labels are optional, and are used to clarify semantics of the relationship 30

Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. (customer-id, account-number) is the super key of depositor This means that a pair of entities can have at most one relationship in a particular relationship set. E.g. if we wish to track all access-dates to each account by each customer, we cannot assume a relationship for each access. Solution: use a multivalued attribute for access dates. Must consider the mapping cardinality of the relationship set when deciding the candidate keys 31

E-R Diagram with a Ternary Relationship Suppose employees of a bank may have jobs (responsibilities) at multiple branches, with different jobs at different branches. Then there is a ternary relationship set between entity sets employee, job and branch 32

Binary Vs. Non-Binary Relationships Some relationships that appear to be non-binary may be better represented using binary relationships E.g. A ternary relationship parents, relating a child to his/her father and mother, is best replaced by two binary relationships, father and mother Using two binary relationships allows partial information (e.g. only mother being known) But there are some relationships that are naturally non-binary E.g. works-on 33

Weak Entity Sets An entity set that does not have a primary key is referred to as a weak entity set. The existence of a weak entity set depends on the existence of a identifying entity set it must relate to the identifying entity set via a total, one-to-many relationship set from the identifying to the weak entity set Identifying relationship depicted using a double diamond The discriminator (or partial key) of a weak entity set is the set of attributes that distinguishes among all the entities of a weak entity set. The primary key of a weak entity set is formed by the primary key of the strong entity set on which the weak entity set is existence dependent, plus the weak entity set s discriminator. 34

Weak Entity Sets (Cont.) We depict a weak entity set by double rectangles. We underline the discriminator of a weak entity set with a dashed line. payment-number discriminator of the payment entity set Primary key for payment (loan-number, payment-number) 35

Another example of weak entity type EmpNo Employee Emp_Dep Name Dependent Age A child may not be old enough to have a HKID number Even if he/she has a HKID number, the company may not be interested in keeping it in the database. 36

ISA (`is a ) Hierarchies ssn name lot Employees As in C++, or other PLs, attributes are inherited. hourly_wages If we declare A ISA B, every A entity is also considered to be a B entity. hours_worked Hourly_Emps ISA contractid Contract_Emps Overlap constraints: Can Joe be an Hourly_Emps as well as a Contract_Emps entity? (Allowed/disallowed) Covering constraints: Does every Employees entity also have to be an Hourly_Emps or a Contract_Emps entity? (Yes/no) Reasons for using ISA: To add descriptive attributes specific to a subclass. To identify entities that participate in a relationship. 37

Summary of Symbols (Cont.) 38

ER Design Decisions - Attribute vs Entity For each employee we want to store the office number, location of the office (e.g., Building A, floor 6), and telephone. Several employees share the same office Office as attribute Employee_id Office_number Office_location Name Employee Office_phone Employee_id Office as entity Office_number Office_location Name Employee Office Office_phone 39

ER Design Decisions - Entity vs Relationship You want to record the period that an employ works for some department. ssn name lot from to did dname budget Employees Works_In2 Departments ssn name lot did dname budget Employees Works_In3 Departments from Duration to 40

ER Design Decisions - Strong vs. Weak Entity Example: What if in the accounts example an account must be associated with exactly one branch two different branches are allowed to have accounts with the same number. Number Branch_id Account Branch 41