Relational Databases CPSC 315 – Programming Studio Spring 2013 Project 1, Lecture 2 Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch.

Slides:



Advertisements
Similar presentations
Convert ER to Relational Database Entity relation Entity relation Attributes attributes Attributes attributes Primary key primary key Primary key primary.
Advertisements

Database Management Systems Chapter 3 The Relational Data Model (I) Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
Overview of Database Systems CPSC 315 – Programming Studio Spring 2009 Team Project 1, Lecture 1.
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.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Databases : Relational Model 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman distributes.
Chapter 4 Notes. Entity-Relationship Model E/R Diagrams Weak Entity Sets Converting E/R Diagrams to Relations.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. Database Management Systems I Alex Coman, Winter 2006 Entity-Relationship.
SQL Queries CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 4 Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch.
Database Implementation Issues CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 5 Slides adapted from those used by Jennifer Welch.
From ER Diagrams to the Relational Model Rose-Hulman Institute of Technology Curt Clifton.
1 Announcement Recitation time  Before midterm: 6-7pm, by Earl Wagner  After midterm: 5-6pm, by Yi Qiao Newsgroup safe to subscribe  Will not cause.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations Source: slides by Jeffrey Ullman.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 3 Slides adapted from those used by Jeffrey Ullman, via Jennifer.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Reduction of an E-R Schema to Tables A database which conforms to an E-R diagram can be represented.
CS411 Database Systems Kazuhiro Minami
SQL Overview Defining a Schema CPSC 315 – Programming Studio Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch Via Yoonsuck Choe.
Database System Concepts, 5th Ed. Chapter 6: Entity-Relationship Model.
DATABASE MANAGEMENT SYSTEMS BASIC CONCEPTS 1. What is a database? A database is a collection of data which can be used: alone, or alone, or combined /
DATABASE MANAGEMENT SYSTEMS BASIC CONCEPTS 1. What is a database? A database is a collection of data which can be used: alone, or alone, or combined /
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations.
Chapter 3: Relational Model I Structure of Relational Databases Structure of Relational Databases Convert a ER Design to a Relational Database Convert.
Databases : Entity-Relationship Model 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman.
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
EXAMPLE. Subclasses and Superclasses Entity type may have sub-grouping that need to be represented explicitly. –Example: Employee may grouped into.
1 Session 2 Welcome: The seventh learning sequence “ Reduction of an EER schema to tables“ Recap : In the previous learning sequence, we discussed the.
IS 230Lecture 4Slide 1 Entity Relationship to Relational Model Mapping Lecture 5.
CS 405G: Introduction to Database Systems Lecture 2 : Database Design I.
© D. Wong Ch. 2 Entity-Relationship Data Model (continue)  Data models  Entity-Relationship diagrams  Design Principles  Modeling of constraints.
Entity-Relationship Model
 Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.
ICOM 5016 – Introduction to Database Systems Lecture 9 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Entity Relationship Diagram (2)
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.
Mapping E/R Diagrams to Relational Database Schemas
Databases 1 Fifth lecture. Entity-Relationship Model Diagrams Class hierarchies Weak entity sets From E/R diagrams to Relations 2.
DatabaseIM ISU1 Chapter 7 ER- and EER-to-Relational Mapping Fundamentals of Database Systems.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
The Entity-Relationship Model CIS 4301 Lecture Notes 1/12/2006.
Chapter 2: Entity-Relationship Model. 3.2 Chapter 2: Entity-Relationship Model Design Process Modeling Constraints E-R Diagram Design Issues Weak Entity.
1 Unified Modeling Language. 2 UML  UML is designed to model software, but has been adapted as a database modeling language. – No multiway relationships.
SQL Overview CPSC 315 – Programming Studio Spring 2013 Project 1, Part 3 Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch.
CS422 Principles of Database Systems Convert ER Design to Relations Chengyu Sun California State University, Los Angeles.
CS422 Principles of Database Systems Entity-Relationship Model Chengyu Sun California State University, Los Angeles.
High-level Database Models Prof. Yin-Fu Huang CSIE, NYUST Chapter 4.
A short revision on entity- relationship modelling.
A short review on entity- relationship modelling.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations.
CS422 Principles of Database Systems From ER to Relations Chengyu Sun California State University, Los Angeles Adapted from Jeffrey Ullman’s lecture notes.
Relational Database Design by ER- and EER-to- Relational Mapping
Entity-Relationship Model
CPSC-310 Database Systems
CPSC 315 – Programming Studio Fall 2009 Project 1, Lecture 2
CSCE 315, Fall 2017 Project 1, Lecture 2
CPSC-310 Database Systems
Transformation of E/R Diagram to Relation
Overview of Database Systems
Database Implementation Issues
Overview of Database Systems
CSCE 315 – Programming Studio Spring 2010 Project 1, Lecture 4
Overview of Database Systems
DATABASE IMPLEMENTATION ISSUES
Lecture 5: The Relational Data Model
The Relational Data Model
Database Implementation Issues
Overview of Database Systems
Session 5: Weak Entity Sets and ER Model to Relational ( )
Database Implementation Issues
CPSC 315 – Programming Studio Spring 2017 Project 1, Part 3
Presentation transcript:

Relational Databases CPSC 315 – Programming Studio Spring 2013 Project 1, Lecture 2 Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch

Relational Data Model Relations are stored in tables e.g. Sponsor(Senator,Bill) Sponsor SenatorBill SmithTax JonesDefense SmithDefense AdamsCommerce Atrributes Tuples

Schemas A relation schema is a relation name and a list of attributes Sponsor(Senator,Bill) A database is a collection of relations A database schema is the set of all the relation schemas in the database

Converting from Entity- Relationship Model ER: Entity set -> relation ER Attributes become Relational attributes ER: Relationship -> relation Keys of connected ER entity sets become Relational attributes

ER Entity Sets Senator Name State Party Years NameText Bill Name Organization Lobbyist

Relations Senator(Name,Party,State,Years) Bill(Name,Text) Lobbyist(Name,Organization)

ER Relationships Senator Name State Party Years NameText Bill Sponsored Name Organization Lobbyist Wrote Contributed

Relations Sponsored(Senator,Bill) Wrote(Bill,Lobbyist) Contributed(Senator,Lobbyist) Remember, each of these is expressed as a table (with the columns given by the “parameters”) Notice that columns can refer to “bigger” items, with even more attributes

Combining Relations Relations can sometimes be combined. Assume a “base” entity set with its relation. If there is a many-to-one relation, then it can be combined with the base entity set. Should not combine many-to-many Would cause redundancy – each of the many stored

Combining Relations Example (many-to-one): (Good) Person(Name, Birthdate, Height, Weight, Eye Color, Hair Color) BornIn(Person,Town) Person(Name, Birthdate, Height, Weight, Eye Color, Hair Color, Town) Example(many-to-many): (Bad) Senator(Name, Party, State, Years) Sponsored(Senator, Bill) Senator(Name, Party, State, Years, Bill)

Weak Entity Sets The relation for a weak entity set must contain all the elements of its key Supporting relationships are usually redundant (unless possibly multi-way)

Weak Entity Set Example Baseball Player First Name Last Name Number Position NationalitySalary Birthdate Name Team Plays On City Note arrrow: indicates many to one.

Weak Entity Set Example Team(Name, City) Baseball Player(Number, TeamName, First Name, Last Name, Position, Birthdate, Nationality, Salary)

Weak Entity Set Example Team(Name, City) Baseball Player(Number, TeamName, First Name, Last Name, Position, Birthdate, Nationality, Salary) Note that we don’t need PlaysOn(BaseballPlayer.Number, BaseballPlayer.TeamName, Team.Name)

Weak Entity Set Example Team(Name, City) Baseball Player(Number, TeamName, First Name, Last Name, Position, Birthdate, Nationality, Salary) Note that we don’t need PlaysOn(BaseballPlayer.Number, BaseballPlayer.TeamName, Team.Name) Redundant (same)

Weak Entity Set Example Team(Name, City) Baseball Player(Number, TeamName, First Name, Last Name, Position, Birthdate, Nationality, Salary) Note that we don’t need PlaysOn(BaseballPlayer.Number, BaseballPlayer.Team.Name)

Weak Entity Set Example Team(Name, City) Baseball Player(Number, TeamName, First Name, Last Name, Position, Birthdate, Nationality, Salary) Note that we don’t need PlaysOn(BaseballPlayer.Number, BaseballPlayer.Team.Name) Already Included

Subclasses Different Options Different ways to represent subclasses U.S. Representative District Elected Official Name Party isa

Object-Oriented Style One relation for each subset, including all “inherited” attributes Elected Official NameParty Bill FloresRepublican Lloyd DoggettDemocrat John AdamsFederalist Joe BartonRepublican U.S. Representative NamePartyDistrict Bill FloresRepublican17 Joe BartonRepublican6 Lloyd DoggettDemocrat25

Entity-Relationship Style One relation for each subclass (including key) Elected Official NameParty Bill FloresRepublican Lloyd DoggettDemocrat John AdamsFederalist Joe BartonRepublican U.S. Representative NameDistrict Bill Flores17 Joe Barton6 Lloyd Doggett25

Using Nulls Style One relation total, with nulls for unknown information Can save space, but problematic if multiple subclasses or lots of NULLs U.S. Representative NamePartyDistrict Bill FloresRepublican17 Lloyd DoggettDemocrat25 John AdamsFederalistNULL Joe BartonRepublican6

Keys A Key “functionally determines” all other attributes of the relation Given a relation and a key, there is only one tuple that corresponds to it There are subtle differences from an E- R key, which we won’t go into.