The Relational Model 01/28/2014 – Material from Chapter 4 (Chap2 and Chap3 make an appearance)

Slides:



Advertisements
Similar presentations
Entity-Relationship (ER) Modeling
Advertisements

Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Relational Model (CB Chapter 4) CPSC 356 Database Ellen Walker Hiram College.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Entity Relationship (ER) Modeling
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 4 Entity Relationship (ER) Modeling.
Entity Relationship (ER) Modeling
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
1 Translation of ER-diagram into Relational Schema Prof. Sin-Min Lee Department of Computer Science.
Modeling Data The Entity Relationship Model (ER) For Database Design.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
The Entity-Relationship Data Model
The Relational Database Model. 2 Objectives How relational database model takes a logical view of data Understand how the relational model’s basic components.
Chapter 4 Entity Relationship (ER) Modeling
Database Systems: Design, Implementation, and Management Tenth Edition
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Chapter 5 Relational Model Concepts Dr. Bernard Chen Ph.D. University of Central Arkansas.
Entity Relationship Model Chapter 6. Basic Elements of E-R Model Entity Object of the real world that stores data. Eg. Customer, State, Project, Supplier,
Entity Relationship Modeling Objectives: To illustrate how relationships between entities are defined and refined. To know how relationships are incorporated.
3 The Relational Model MIS 304 Winter Class Objectives That the relational database model takes a logical view of data That the relational model’s.
Relational Model Session 6 Course Name: Database System Year : 2012.
4 1 Chapter 4 Entity Relationship (ER) Modeling Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
CS411 Database Systems Kazuhiro Minami 02: The Entity-Relationship Model.
CG084&085 / / 1 The Relational Data Model Properties of Relations Keys and Constraints.
CPSC 603 Database Systems Lecturer: Laurie Webster II, M.S.S.E., M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 3 Introduction to a First Course in Database Systems.
Copyright 2008 McGraw-Hill Ryerson 1 TECHNOLOGY PLUG-IN T5 DESIGNING DATABASE APPLICATIONS.
The Relational Database Model
McGraw-Hill/Irwin © 2008 The McGraw-Hill Companies, All Rights Reserved Plug-In T5: Designing Database Applications Business Driven Technology.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
1.1 CAS CS 460/660 Relational Model. 1.2 Review E/R Model: Entities, relationships, attributes Cardinalities: 1:1, 1:n, m:1, m:n Keys: superkeys, candidate.
1 Relational Databases and SQL. Learning Objectives Understand techniques to model complex accounting phenomena in an E-R diagram Develop E-R diagrams.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 4 Entity Relationship (ER) Modeling.
Chapter 4 Entity Relationship (ER) Modeling.  ER model forms the basis of an ER diagram  ERD represents conceptual database as viewed by end user 
Relational Database. Database Management System (DBMS)
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
3 & 4 1 Chapters 3 and 4 Drawing ERDs October 16, 2006 Week 3.
Data Modeling Using the Entity-Relationship (ER) Model.
© D. Wong Ch. 2 Entity-Relationship Data Model (continue)  Data models  Entity-Relationship diagrams  Design Principles  Modeling of constraints.
Database Systems: Design, Implementation, and Management Ninth Edition Chapter 4 Entity Relationship (ER) Modeling.
CPSC 603 Database Systems Lecturer: Laurie Webster II, M.S.S.E., M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 2 Introduction to a First Course in Database Systems.
Databases Illuminated Chapter 3 The Entity Relationship Model.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 4 ENTITY RELATIONSHIP (ER) MODELING Instructor Ms. Arwa Binsaleh 1.
Home Work. Design Principles and Weak Entity Sets.
Announcements Reading for Monday –4.6 Homework 3 – Due 9/29.
12/2/2015CPSC , CPSC , Lecture 41 Relational Model.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
advanced data modeling
CS 157B Database Systems Dr. T Y Lin. Updates 1.Red color denotes updated data (ppt) 2.Class participation will be part of “extra” credits to to “quiz.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 5 – September 4 th,
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
The Entity-Relationship Model CIS 4301 Lecture Notes 1/12/2006.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
Chapter 3 The Relational Database Model. Database Systems, 10th Edition 2 * Relational model * View data logically rather than physically * Table * Structural.
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
ERD :: 19 / 1 / Entity-Relationship (ER) Modeling. ER Modeling is a top-down approach to database design. Entity Relationship (ER) Diagram –A.
High-level Database Models Prof. Yin-Fu Huang CSIE, NYUST Chapter 4.
Modeling: Entity-Relationship Diagrams
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
ER Diagrams and Relational Model CS 174a (Winter 2015)
Entity Relationship Modeling
Tables and Their Characteristics
Database Systems: Design, Implementation, and Management Tenth Edition
MIS2502: Data Analytics Relational Data Modeling
Database Modeling using Entity Relationship Model (E-R Model)
MIS2502: Data Analytics Relational Data Modeling 2
Presentation transcript:

The Relational Model 01/28/2014 – Material from Chapter 4 (Chap2 and Chap3 make an appearance)

Project Proposal - ???’s  Added some clarification.  What questions do you have about the project?  Data sets are available online at  psql –h db.cs.jmu.edu vlds – to play with the data  if already inside psql \c databaseName

Homework debrief  Scripts – If all is working correctly, you can run through psql.  psql –h hostname –f filename  -- comment to end of line (inline comment)  /* C-like comment, possibly multiple lines */ (block comment)  easier to build a text file and cut and paste commands in. Easier to change.  Can also use the –e option in psql to echo queries sent to server to standard output. > to pipe to a file.

Datatypes   Of note: varchar (n). Will save a maximum of n characters in the corresponding field.  If all of that space is not needed, then it will use less space.  money  date and time types

Review acctNotypebalance 12345savings checking savings25.25 firstNamelastNameidNoaccount RobbieBanks LenaHand LenaHand a.attributes b.tuples c.one tuple from each relation d.relation schema e.database schema f.a domain for each attribute g.an equivalent relation h.a possible key to the relation

Review Exercise – Accounts(balance : float, acctNo : integer, type : string) firstNamelastNameidNoaccount RobbieBanks LenaHand LenaHand Customer(firstName : string, lastName : string, idNo : string, account : integer) a.attributes b.tuples c.one tuple from each relation d.relation schema e.database schema f.a domain for each attribute g.an equivalent relation h.a possible key to the relation acctNotypebalance 12345savings checking savings25.25

Model (freeonlinedictionary.com) A schematic description of a system, theory, or phenomenon that accounts for its known or inferred properties and may be used for further study of its characteristics: a model of generative grammar; a model of an atom; an economic model; a database model. Gives us a way of understanding the database and the interaction among its objects.

Design vs Implementation Ideas High level design Database Schema Relational DBMS

The Relational Model itself  The database is formed from a series of interconnected tables.  Each table has one or more attributes (fields).  Each table has zero or more rows (tuples).  Tables can be connected by keys.

How do we express that model in design?  Various design tools  ER Diagramming (Peter Chen – 1976) (Remember Codd’s paper in 1970)  Databases can be expressed as “entities” who are connected by “relationships”.

From Chen’s paper

In the ER-Diagram Chen Style Entity Relation- ship Attribute Teacher Teaches Classes Number Name Id Class

Multiplicity  Each connection can have a number associated with it.  1:1 – one to one - each entity in one relation has at most one entity in the other and vice versa.  ex: a faculty member and their office.  1:M – one to many – each entity in one relation has many related entities in another.  ex: one faculty member teaches many courses but each course is taught by only one faculty member.  M:M (often shown as M:N) many to many - each entity in one relation may have many related entities in another and vice versa.  ex: a supplier supplies many products and each product is supplied by many suppliers.

In the ER-Diagram Chen Style Entity Relation- ship Attribute Teacher Teaches Classes Number Name Id Class 1 M

Instances  Each ERD describes a database schema.  If that schema is realized as a database, an instance of the database is a snapshot of the database at a particular period of time.

A database instance Accounts(balance : float, acctNo : integer, type : string) firstNamelastNameidNoaccount RobbieBanks LenaHand LenaHand Customer(firstName : string, lastName : string, idNo : string, account : integer) acctNotypebalance 12345savings checking savings25.25

Keys (Chapter 3.1.2)  “A key for an entity set E is a set K of one or more attributes such that, given any two distinct entities e 1 and e 2 in E, e 1 and e 2 cannot have identical values for each of the attributes in the key.” Ullman  A key is a set of attributes that uniquely define a row of a table.  There may be more than one key. One is selected as the primary key.  One additional requirement – No proper subset of the key attributes can themselve be a key.

Keys  Person(id, , last, first, dob, SSN)  id, , last-first-dob, SSN may all be considered keys.  id- , last-first-dob-SSN would not be keys. In each, there is a proper subset of elements that itself is a key.  We would call id- and last-first-dob-SSN superkeys…a set of attributes that contain a key.  Every key is a superkey but not every superkey is a key.  We sometimes use the term candidate keys for the possible keys to the relation. From the candidates, a single key is chosen.

Keys in ERD Movies Own Studios Runs Presidents titleyear genrelength Id name composite key

Movies Own Studios Runs Presidents So what does this ERD tell us? Constraints (Referential Integrity) The curve arrow is a 1 relationship. The filled arrow is a 0..1 relationship. (I may have a studio that does not currently have a president, but if I have a president, she must run a studio.) A studio may own 0..* Movies, but a Movie must be owned by a single Studio. Many-one relationship->optional tuple Referential integrity  required tuple

Movies Own Studios Runs Presidents Alternate expression of the same idea Constraints (Referential Integrity) The curve arrow is a 1 relationship. The filled arrow is a 0..1 relationship. (I may have a studio that does not currently have a president, but if I have a president, she must run a studio.) A studio may own 0..* Movies, but a Movie must be owned by a single Studio m

Other kinds of relationships - self Movies sequel of original A movie may have many sequels, but a sequel can have only one original. sequel

Other kinds of relationships - multiway Movies Contracts Studios Stars A contract is between a star, the movie that star is in, the producing studio and the star’s contracting studio. Producing studio, the arrow implies that there is at most one producing studio Stars’ studios, the arrow implies a star can have at most one studio pay

Other diagramming tools  Crow’s Foot  UML – See Chapter 4.7 Movies PK title PK year length genre Studios Presidents PK Id name own minimum cardinality maximum cardinality Means, a movie must be owned by one and only one studio. A studio may own no or many movies. Means a studio may have one or no presidents, but if there is a president then she must preside over exactly one studio.

Some other terms  Weak entity (represented by double lines)  An entity that depends upon the existence of another. Usually it will have as one of its key components the key from another table.  Ex. A student-class table is a weak entity of student and class as it depends on both.  We will see that relationships are often implemented as tables within a db. They become weak entities.

Design considerations  While we will be looking more at design through the semester, a few things of note:  Faithfulness (or fitfulness) – The data should “faithfully” represent the underlying real world model and be “fit” for the application.  Ex: Stars and Movies – Implies a many to many relationship since movies have multiple stars and stars appear in multiple movies.  It also depends on the enterprise in which the data will be used.  A school that has no “team” teaching could say one teacher teaches many courses but a class can only be taught by one teacher vs  JMU which has team teaching so we have a many to many relationship between teachers and courses.

Design  Avoid redundancy – Redundant data is often inconsistent data.  Simplicity – Avoid extra elements or elements that do not support the enterprise.  Choosing the right relationships – Look at the relationships among the entities and determine the best way to represent them. (See diagram 143)  What is right for the type of element? Is it an attribute of an entity or a standalone entity in its own right? Is it an entity or simply a relationship between entities.

Design  Choose the right data elements (Atomicity)  Do we make name an attribute or do we break it up into first middle last. name can be derived from the individual data.  Avoid derived data (Staleness)  Data that can be derived from other data perhaps does not belong in the db.  If I have date of birth I can derive age at any time that I need it.  If I have vendor transactions, I can derive the total amount purchased.

Design – Referential Integrity  Where do we want to enforce the notion of required tuples?  When must we have a corresponding row?  Sometimes we build tables to help us maintain data integrity.