CSIT5300: Advanced Database Systems

Similar documents
Comp 5311 Database Management Systems. 2. Relational Model and Algebra

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

Chapter 2: Entity-Relationship Model

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

CSIT5300: Advanced Database Systems

Chapter 6: Entity-Relationship Model

Database System Concepts

Chapter 6: Entity-Relationship Model

CS275 Intro to Databases

COMP Instructor: Dimitris Papadias WWW page:

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

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

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

CSIT5300: Advanced Database Systems

Chapter 7: Entity-Relationship Model

Domain Constraints Referential Integrity Assertions Triggers. Authorization Authorization in SQL

Chapter 7: Entity-Relationship Model

DATABASE TECHNOLOGY - 1MB025 (also 1DL029, 1DL300+1DL400)

DATABASE TECHNOLOGY - 1DL124

ACS-3902 Fall Ron McFadyen 3D21 Slides are based on chapter 5 (7 th edition) (chapter 3 in 6 th edition)

Chapter 7: Entity-Relationship Model

CSIT5300: Advanced Database Systems

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

Chapter 4. The Relational Model

Chapter 3: Relational Model

Entity-Relationship Model

Chapter 6: Entity-Relationship Model

Unit I. By Prof.Sushila Aghav MIT

Chapter 7: Entity-Relationship Model

The Relational Model

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

Relational Model. Rab Nawaz Jadoon DCS. Assistant Professor. Department of Computer Science. COMSATS IIT, Abbottabad Pakistan

The Basic (Flat) Relational Model. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

DATABASE DESIGN I - 1DL300

Chapter 6: Entity-Relationship Model

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

CSCC43H: Introduction to Databases

Database Design and the E-R Model (7.4, )

CS34800 Information Systems. The Relational Model Prof. Walid Aref 29 August, 2016

Running Example Tables name location

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

Relational model continued. Understanding how to use the relational model. Summary of board example: with Copies as weak entity

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

Normal Forms. Winter Lecture 19

CS425 Fall 2016 Boris Glavic Chapter 2: Intro to Relational Model

COSC344 Database Theory and Applications. σ a= c (P) Lecture 3 The Relational Data. Model. π A, COSC344 Lecture 3 1

NORMAL FORMS. CS121: Relational Databases Fall 2017 Lecture 18

Chapter 6: Relational Database Design

We shall represent a relation as a table with columns and rows. Each column of the table has a name, or attribute. Each row is called a tuple.

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

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

Intro to DB CHAPTER 6

1. Considering functional dependency, one in which removal from some attributes must affect dependency is called

Chapter 2: Intro to Relational Model

Chapter 2: Relational Model

Relational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions.

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

Introduction to Relational Databases. Introduction to Relational Databases cont: Introduction to Relational Databases cont: Relational Data structure

Comp 5311 Database Management Systems. 4b. Structured Query Language 3

How to translate ER Model to Relational Model

Database Technology Introduction. Heiko Paulheim

ER to Relational Model. Professor Jessica Lin

The data structures of the relational model Attributes and domains Relation schemas and database schemas

UNIT II A. ENTITY RELATIONSHIP MODEL

DATABASE TECHNOLOGY. Spring An introduction to database systems

Chapter 1: Introduction

The En'ty Rela'onship Model

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

Chapter 2 Introduction to Relational Models

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

6.1 RELATIONSHIP CONCEPTS

Roadmap of This Lecture. Weak Entity Sets Extended E-R Features Reduction to Relation Schemas Database Design UML*

Database Applications (15-415)

Database Applications (15-415)

DATABASE DESIGN - 1DL400

Lecture 10 - Chapter 7 Entity Relationship Model

Entity-Relationship Model &

The Relational Model 2. Week 3

Database Management Systems LECTURE NOTES 2

The Relational Model. Week 2

Example: specific person, company, event, plant

DATABASE DESIGN - 1DL400

Introduction to Databases

Lecture 11 - Chapter 8 Relational Database Design Part 1

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

Relational Model. CS 377: Database Systems

High Level Database Models

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

Relational Database Design (II)

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

Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra

Data about data is database Select correct option: True False Partially True None of the Above

Chapter 3. The Relational database design

CS 377 Database Systems

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

The Relational Model

Chapter 8: Relational Database Design

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

The Entity Relationship Model

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

Transcription:

CSIT5300: Advanced Database Systems L02: Relational Data Model Dr. Kenneth LEUNG Department of Computer Science and Engineering The Hong Kong University of Science and Technology Hong Kong SAR, China kwtleung@cse.ust.hk CSIT5300

Basic Concepts of the Relational Model Entities and relationships of the E-R model are stored in tables also called relations (not to be confused with relationships in the E-R model) Benefits: - There can be well-defined semantics and languages for manipulating the tables - Ease of implementation write queries on tables without caring about the physical level and optimization issues Most popular DBMSs today are based on the relational data model (or an extension of it, e.g., object-relational data model) kwtleung@cse.ust.hk CSIT5300 2

Terminology Relation table: denoted by R(A 1, A 2,..., A n ) where R is a relation name and (A 1, A 2,..., A n ) is the relation schema of R Attribute (column) denoted by A i Tuple (Record) row Attribute value value stored in a table cell Domain legal type and range of values of an attribute denoted by dom(a i ) Attribute: Age Domain: [0-100] Attribute: EmpName Domain: 50 alphabetic chars Attribute: Salary Domain: non-negative integer kwtleung@cse.ust.hk CSIT5300 3

An Example Relation Relation Name/Table Name Attributes/Columns (collectively as a schema) STUDENT Name Student-id Age CGA Chan Kin Ho 99223367 23 11.19 Lam Wai Kin 96882145 17 10.89 Man Ko Yee 96452165 22 8.75 Lee Chin Cheung 96154292 16 10.98 Alvin Lam 96520934 15 9.65 kwtleung@cse.ust.hk CSIT5300 4

Some Formal Definitions A relation schema is denoted by: R(A 1, A 2,..., A n ) STUDENT(Name, Student-id, Age, CGA) Degree of a relation: the number of attributes n in the relation. Tuple t of R(A 1, A 2,..., A n ): An ordered set of values <v 1,v 2,...,v n > where each v i is an element of dom(a i ). Relation instance r(r): A set of tuples in R. - r(r) = {t 1, t 2,..., t m }, or alternatively r(r) dom(a 1 ) dom(a 2 )... dom(a n ) kwtleung@cse.ust.hk CSIT5300 5

Relation and Cartesian Product A relation is any subset of the Cartesian product of the domains of values Example: Let Dom(Name) = { Lee, Cheung } Dom(Grade) = { A, B, C } Then the Cartesian product of the domains is Dom(Name) Dom(Grade) = { <Lee, A>, <Lee, B >, <Lee, C>, <Cheung, A>, <Cheung, B>, <Cheung C> } A relation StudentGrade(Name, Grade) can be defined as any subset of the Cartesian product Dom(Name) Dom(Grade), e.g., r(studentgrade) = { <Lee, A>, <Cheung C> } Dom(Name) Dom(Grade) kwtleung@cse.ust.hk CSIT5300 6

Characteristics of Relations Tuples in a relation are not considered to be ordered, even though they appear to be in a tabular form (recall that a relation is a set of tuples) All attribute values are considered atomic. Multivalued and composite attribute values are not allowed in tables, although they are permitted by the E-R diagrams A special null value is used to represent values that are: Not applicable (phone number for a client that has no phone) Missing values (there is a phone number, but we do not know it yet) Not known (we do not know whether there is a phone number or not) kwtleung@cse.ust.hk CSIT5300 7

Keys Let K R (i.e., K is a set of attributes which is a subset of the schema of R) K is a superkey of R, if K can identify a unique tuple in a given instance r(r) Example: Student(SID, HKID, Name, Address, ) where SID and HKID are unique Possible superkeys: {SID} {HKID} {SID, Name} {HKID, Name, Address} plus many others K is a candidate key if K is minimal In the above example there are two candidate keys: SID and HKID Every relation must have at least one candidate key If there are multiple, one is chosen as the primary key kwtleung@cse.ust.hk CSIT5300 8

Need for Multiple Tables Storing all information as a single relation such as bank(account-number, balance, customer-name, customer-addr,..) results in repetition of information (e.g. repeat the customer info for each of his/her accounts) the need for null values (e.g. represent a customer without an account) That is why we need the E-R diagrams (and some additional normalization techniques discussed later) to break up information into parts, with each relation storing one part Example: Account : stores information about accounts Customer : stores information about customers Depositor : stores information about which customer owns which account kwtleung@cse.ust.hk CSIT5300 9

Reduction of an E-R Diagram to Relations A database which conforms to an E-R diagram can be represented by a collection of tables. Converting an E-R diagram to a table format is automatic. For each entity set there is a unique table which is assigned the name of the corresponding entity set. Each table has a number of columns (generally corresponding to attributes), which have unique names. kwtleung@cse.ust.hk CSIT5300 10

Composite and Multivalued Attributes Composite attributes are flattened out by creating a separate attribute for each component attribute E.g., given entity set customer with composite attribute name comprised of first-name and last-name, the customer table has two attributes: name.first-name and name.last-name A multivalued attribute M of an entity E is represented by a separate table EM Table EM has attributes corresponding to the primary key of E and an attribute corresponding to multivalued attribute M Example: Multivalued attribute phone-number of employee is represented by a table employee-phone(employee-id, phone-number) Each value of the multivalued attribute maps to a separate row of the table EM E.g., an employee with primary key 19444 and phones 23580000, 95555555 maps to two rows: (19444, 23580000) and (19444, 95555555) kwtleung@cse.ust.hk CSIT5300 11

Representing Weak Entities A weak entity set becomes a table that includes a column for the primary key of the identifying strong entity set kwtleung@cse.ust.hk CSIT5300 12

Representing Relationship Sets as Tables A many-to-many relationship set is represented as a table with columns for the primary keys of the two participating entity sets, and any descriptive attributes of the relationship set Example: table for relationship set borrower kwtleung@cse.ust.hk CSIT5300 13

Representing Relationship Sets as Tables (cont.) Many-to-one and one-to-many relationship sets that are total on the manyside can be represented by adding an extra attribute to the many side, containing the primary key of the one side Example: Instead of creating a table for relationship account-branch, add the key of branch (branch-name) to the entity set account branch-name in account is a foreign key kwtleung@cse.ust.hk CSIT5300 14

Representing Relationship Sets as Tables (cont.) For one-to-one relationship sets, either side can be chosen to act as the many side in the previous slide That is, extra an attribute can be added to either of the tables corresponding to the two entity sets If participation is partial on the many side, adding an extra attribute in the relation corresponding to the many side could result in null values (redundancy) Maybe it is better to represent the relationship set by a separate table as in the many-to-many case The table corresponding to a relationship set linking a weak entity set to its identifying strong entity set is redundant Example: The paymen table already contains the information that would appear in the loan-paymen table (i.e., the columns loan-number and paymentnumber). kwtleung@cse.ust.hk CSIT5300 15

Representing ISA as Tables Method 1: Form a table for the higher level entity Form a table for each lower level entity set, and include the primary key of the higher level entity set and local attributes Example: table person customer employee table attributes id, name, street, city id, credit-rating id, salary Drawback: getting information about, e.g., employee, requires accessing two tables kwtleung@cse.ust.hk CSIT5300 16

Representing ISA as Tables (cont.) Method 2: Form a table for each entity set with all local and inherited attributes Example: table person customer employee table attributes id, name, street, city id, name, street, city, credit-rating id, name, street, city, salary If the specialization is total, no need to create a table for the generalized entity (person) Drawback: street and city may be stored redundantly for persons who are both customers and employees kwtleung@cse.ust.hk CSIT5300 17