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

Similar documents
Modeling access. Relational query languages. Queries. Selection σ P (R) Relational model: Relational algebra

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

Why Study the Relational Model? The Relational Model. Relational Database: Definitions. The SQL Query Language. Relational Query Languages

Chapter 2: Intro to Relational Model

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

Relational Query Languages: Relational Algebra. Juliana Freire

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

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

Relational Algebra. Lecture 4A Kathleen Durant Northeastern University

The Relational Model. Week 2

Relational Model, Relational Algebra, and SQL

Chapter 2: Intro to Relational Model

Relational Model and Relational Algebra. Rose-Hulman Institute of Technology Curt Clifton

Database System Concepts, 5 th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "

Relational Query Languages. Preliminaries. Formal Relational Query Languages. Example Schema, with table contents. Relational Algebra

2.2.2.Relational Database concept

Database Applications (15-415)

Database Technology Introduction. Heiko Paulheim

Announcements. Relational Model & Algebra. Example. Relational data model. Example. Schema versus instance. Lecture notes

Relational Model & Algebra. Announcements (Thu. Aug. 27) Relational data model. CPS 116 Introduction to Database Systems

Relational Algebra. Study Chapter Comp 521 Files and Databases Fall

v Conceptual Design: ER model v Logical Design: ER to relational model v Querying and manipulating data

Relational Algebra. [R&G] Chapter 4, Part A CS4320 1

Lecture Notes for 3 rd August Lecture topic : Introduction to Relational Model. Rishi Barua Shubham Tripathi

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

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

Domain Constraints Referential Integrity Assertions Triggers. Authorization Authorization in SQL

The Relational Model 2. Week 3

Relational Algebra. Note: Slides are posted on the class website, protected by a password written on the board

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

Part I: Structured Data

CS2300: File Structures and Introduction to Database Systems

Relational Algebra 1. Week 4

CS530 Database Architecture Models. Database Model. Prof. Ian HORROCKS. Dr. Robert STEVENS. and Design The Relational

Database Management Systems. Chapter 4. Relational Algebra. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

Chapter 3: Relational Model

Database Applications (15-415)

Chapter 2: Relational Model

PES Institute of Technology Bangalore South Campus (1 K.M before Electronic City,Bangalore ) Department of MCA. Solution Set - Test-II

Chapter 3. The Relational Model. Database Systems p. 61/569

Relational Model & Algebra. Announcements (Tue. Sep. 3) Relational data model. CompSci 316 Introduction to Database Systems

The Relational Model

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

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

The Relational Model of Data (ii)

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

Where Are We? Next Few Lectures. Integrity Constraints Motivation. Constraints in E/R Diagrams. Keys in E/R Diagrams

Database System Concepts

CMP-3440 Database Systems

Translating an ER Diagram to a Relational Schema

Relational Model: History

Databases. Jörg Endrullis. VU University Amsterdam

Relational Query Languages

Introduction to Data Management. Lecture #11 (Relational Algebra)

ER to Relational Mapping

DATABASDESIGN FÖR INGENJÖRER - 1DL124

The Relational Model. Chapter 3

EECS 647: Introduction to Database Systems

Let s briefly review important EER inheritance concepts

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

The Relational Model

MIS Database Systems Relational Algebra

Relational Algebra Homework 0 Due Tonight, 5pm! R & G, Chapter 4 Room Swap for Tuesday Discussion Section Homework 1 will be posted Tomorrow

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

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

EECS 647: Introduction to Database Systems

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

CS 377 Database Systems

What s a database system? Review of Basic Database Concepts. Entity-relationship (E/R) diagram. Two important questions. Physical data independence

CMSC 424 Database design Lecture 3: Entity-Relationship Model. Book: Chap. 1 and 6. Mihai Pop

CSIT5300: Advanced Database Systems

Lecture #8 (Still More Relational Theory...!)

The Entity-Relationship Model. Overview of Database Design

Web Science & Technologies University of Koblenz Landau, Germany. Relational Data Model

Relational Algebra. Relational Query Languages

CS 377 Database Systems

CS425 Midterm Exam Summer C 2012

Relational Model and Relational Algebra

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

Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

Relational algebra. Iztok Savnik, FAMNIT. IDB, Algebra

The Relational Model. Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC)

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

Relational Model and Relational Algebra

Information Systems (Informationssysteme)

From ER Diagrams to the Relational Model. Rose-Hulman Institute of Technology Curt Clifton

CAS CS 460/660 Introduction to Database Systems. Relational Algebra 1.1

Relational Algebra. Chapter 4, Part A. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

Relational Algebra for sets Introduction to relational algebra for bags

Relational Database: The Relational Data Model; Operations on Database Relations

Midterm Review. Winter Lecture 13

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

The Entity Relationship Model

SQL DDL. CS3 Database Systems Weeks 4-5 SQL DDL Database design. Key Constraints. Inclusion Constraints

Relational Model. CS 377: Database Systems

Chapter 9: Relational DB Design byer/eer to Relational Mapping Relational Database Design Using ER-to- Relational Mapping Mapping EER Model

Introduction to Databases

Relational Query Languages

Relational Algebra 1

Transcription:

COS 597A: Principles of Database and Information Systems Relational model continued Understanding how to use the relational model 1 with as weak entity folded into folded into branches: (br_, librarian, hours) : (ISBN#, copy#, condition, purchase date, br_) br_ is a foreign key referencing branches branches with as strong entity Alternative with as strong entity branches branches folded into folded into branches: (br_, librarian, hours) : (ISBN#, call #, condition, purchase date, br_) br_ is a foreign key referencing branches NEW folded into branches: (br_, librarian, hours) : (ISBN#, call #, condition, purchase date) : (call #, br_) call # is a foreign key referencing br_ is a foreign key referencing branches Board example: Total participation of? : (ISBN#, call #, condition, purchase date, br_) br_ is a foreign key referencing branches capture total participation in and because, represented within versus : (call #, br_) call # is a foreign key referencing br_ is a foreign key referencing branches Board example: Total participation of branches? Can t get constraint applied to all branch tuples without being part of branch relation Total participation of branches in not representable in pure relational definition br_ not null would not capture that every call # value 5 6 is in a pair 1

Attribute R_A 1 Entity 1 Basic Paradigm R Attribute R_A m Entity k Entity Entity k-1 Each entity becomes a relation Relationship becomes R: { (list of attributes forming key of Entity 1 (denote L 1 ), list of attributes forming key of Entity (denote L ), list of attributes forming key of Entity k (denote L k ), Attribute R_A 1,, Attribute R_A m ) L 1 is a foreign key referencing Entity 1, L k is a foreign key referencing Entity k } Note primary key 7 What about constraints on relationships? Key constraint: Simplifies key of corresponding relation Allows folding of relation into key entity Total participation constraint: In general, cannot represent in purely relational definition: Domain specification Keys of relations Foreign keys not null s } Constraints have in relational definition 8 Enforcing relational constraints Constraints must be satisfied at all times What happens when tuples in relations change? Action of changing a relation not part of basic relational model Database language implementing model enforces SQL commands changing relations: INSERT, DELETE, UPDATE Domain constraints Don t allow attribute value not in domain Not null constraints Special case of domain constraints 9 10 Candidate key constraints Can have other candidate keys declared as well as primary key Don t allow nd tuple with same key value Implicit not null for attributes in a key Foreign key constraints Suppose Y denotes a set of attributes of relation B that reference the primary key of relation A. Don t allow tuple into B if no tuple in A with matching values for Y 11 1

Foreign key constraints continued suppose want to remove a tuple in A Suppose there is a tuple in B with matching values for Y Choices (in SQL): 1. Disallow deletion from A DELETE or UPDATE fails Choices (in SQL) continued:. Ripple effect (CASCADE): Remove tuple from A and all tuples from B with matching values for Y DELETE or UPDATE in A causes DELETE in B. Substitute value Put null (if Y not part of candidate key for B) or other default value for Y in B DELETE or UPDATE in A causes UPDATE in B 1 1 Actions for board example? branches: (br_, librarian, hours) : (ISBN#, copy#, condition, purchase date, br_) isbn# is a foreign key referencing s br_ is a foreign key referencing branches What about constraints not expressible in ER model? Value-based constraints? General functional constraints? In relational model: Declaring and enforcing these depend on use of database language Use query semantics to check 15 16 COS 597A: Principles of Database and Information Systems Relational algebra 17 Modeling access Have looked at modeling information as data + structure Now: how model access to data in relational model? Formal specification of access provides: Unambiguous queries Correctness of results Expressiveness of query languages 18

Queries A query is a mapping from a set of relations to a relation Query: relations relation Can derive schema of result from schemas of input relations Can deduce constraints on resulting relation that must hold for any input relations Can identify properties of result relation 19 Relational query languages Two formal relational languages to describe mapping Relational algebra Procedural lists operations to form query result Relational calculus Declarative describes results of query Equivalent expressiveness Each has strong points for usefulness DB system query languages (e.g. SQL) take best of both 0 begin with Relational Algebra Basic operations of relational algebra: 1. Selection σ :select a subset of tuples from a relation according to a condition. Projection π :delete unwanted attributes (columns) from tuples of a relation. cross product X : combine all pairs of tuples of two relations by making tuples with all attributes of both. Set difference :* tuples in first relation and not in second 5. union U:* tuples in first relation or second relation 6. Renaming ρ: to deal with conflicts Selection σ P (R) relation R predicate P on attributes of R resulting relation schema same as R contains those tuples of R that satisfy P candidate keys and foreign keys in R are preserved eliminating tuples doesn t cause violations * Set operations: D 1 X D X D k of two relations must agree 1 Selection Example Students: (, address, gender, age, grad yr) Instance: address gender age grad yr NY M Sally F 5 NJ M Jan F 7 σ age < 5 (Students): (, address, gender, age, grad yr) address gender age grad yr NY M NJ M Projection π S (R) relation R S a list of attributes from R - projected attributes resulting relation: scheme is attributes in S contains all tuples formed by taking a tuple from R and keeping only the attributes listed in S relations are sets duplicates are removed In practice, usually not removed unless explicitly requested if candidate key projected, constraint preserved foreign if no candidate key is projected, only candidate key may be all attributes in S (set model)

Projection Example Students: (, address, gender, age, grad yr) Instance: Sally Jan addr NY NJ gender M F M F age grad yr π, grad yr (Students): (, grad yr) 5 7 Sally Jan grad yr 5 An algebra Composing operators composition works as in other algebras are properties to use to re-order operations Example π, age (σ age < 5 (Students)): σ age < 5 (π, age (Students))? age 6 Set operations for relations R, S D 1 X D X X D k where D i is the domain for the i th attribute i.e. R and S on same universe Union RUS D 1 X D X X D k : contains any tuple in either R or S formal model removes duplicates candidate keys? foreign keys? Set difference R-S D 1 X D X X D k : includes all tuples in R that are not in S constraints left as an exercise 7 Example for Union relations: mayors: (, street address, city, party) legislators: (, street address, city, district, party) X mayors U legislators? not same universe redefine: mayors: (, street address, city, term, party) If term, district both integers same domain can union candidate key of mayors U legislators? 8 Example for Union Set operations revisited relations: mayors: (, street address, city, term, party) legislators: (, street address, city, district, party) candidate key of mayors U legislators? not (city, district) ( Smith, 9 Main St., Kingston, 1, democrat) is mayor of Kingston in his first term ( Sally Jones, 11 River Rd., Kingston, 1, republican) Sally is the legislator from the first district and lives in Kingston foreign key of mayors U legislators? corresponding components need not be the same attribute term versus district 9 for relations R, S D 1 X D X X D k where D i is the domain for the i th attribute i.e. R and S on same universe Union RUS D 1 X D X X D k : contains any tuple in either R or S formal model removes duplicates candidate keys are not generally preserved a foreign key is preserved if it is a foreign key for both R and S using corresponding attributes and referencing the same relation Set difference R-S D 1 X D X X D k : includes all tuples in R that are not in S constraints left as an exercise 0 5