CPSC-310 Database Systems

Slides:



Advertisements
Similar presentations
Union, Intersection, Difference (subquery) UNION (subquery) produces the union of the two relations. Similarly for INTERSECT, EXCEPT = intersection and.
Advertisements

SQL Group Members: Shijun Shen Xia Tang Sixin Qiang.
SQL Queries Principal form: SELECT desired attributes FROM tuple variables –– range over relations WHERE condition about tuple variables; Running example.
CSCI 305 – Fall 2013 The Entity-Relationship Model Based on Slides by Prof. Brian King.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
1 Entity-Relationship Model Diagrams Class hierarchies Weak entity sets.
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.
Entity-Relationship Model. The process of designing a database begins with: –an analysis of what information the database must hold, and –the relationships.
1 Entity-Relationship Model Slides by Jeffrey Ullman Modified by J. Welch to replace beers with candies.
CPSC-608 Database Systems Fall 2009 Instructor: Jianer Chen Office: HRBB 309B Phone: Notes #2.
Entity-Relationship Model
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #3.
1 Entity-Relationship Model Diagrams Class hierarchies Weak entity sets.
What is a Database Management System? 1. Manages very large amounts of data. 2. Supports efficient access to very large amounts of data. 3. Supports concurrent.
CSET 3300 Databases & ER Data Models. Databases A database is a collection of data (information). A DataBase Management System (DBMS) is a software system.
Constraints on Relations Foreign Keys Local and Global Constraints Triggers Following lecture slides are modified from Jeff Ullman’s slides
Databases : Entity-Relationship Model 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman.
Database Management Systems Chapter 2 The Entity-Relationship Data Model Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
1 Entity-Relationship Model Chapter 2 Copyright : Jeff Ullman + Hank Korth.
Entity-Relationship Model
Dale Roberts 11/26/ Department of Computer and Information Science, School of Science, IUPUI Fall 2003 Dale Roberts, Lecturer Computer Science, IUPUI.
Databases 1 Fifth lecture. Entity-Relationship Model Diagrams Class hierarchies Weak entity sets From E/R diagrams to Relations 2.
Entity-Relationship Modelling ER Diagrams and EER Diagrams Some design techniques Elements and process: text  diagram Slides by Jeff Ullman (infolab.stanford.edu/~ullman/dscb/pslides/er.ppt),
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Himanshu GuptaCSE 532-SQL-1 SQL. Himanshu GuptaCSE 532-SQL-2 Why SQL? SQL is a very-high-level language, in which the programmer is able to avoid specifying.
Entity-Relationship Model E/R Diagrams Converting E/R Diagrams to Relations.
A short revision on entity- relationship modelling.
A short review on entity- relationship modelling.
CS422 Principles of Database Systems From ER to Relations Chengyu Sun California State University, Los Angeles Adapted from Jeffrey Ullman’s lecture notes.
Database Design and Programming Jan Baumbach Adopted from previous slides of Peter Schneider-Kamp.
CS422 Principles of Database Systems Entity-Relationship Model Chengyu Sun California State University, Los Angeles Adapted from Jeffrey Ullman’s lecture.
CS422 Principles of Database Systems Entity-Relationship Model
CPSC-310 Database Systems
Session 2 Welcome: To the fourth learning sequence
Entity-Relationship Model
CPSC-310 Database Systems
Schedule Today: Jan. 28 (Mon) Jan. 30 (Wed) Next Week Assignments !!
CPSC-310 Database Systems
Entity-Relationship Diagrams
Outerjoins, Grouping/Aggregation Insert/Delete/Update
Databases : More about SQL
CPSC-310 Database Systems
Example: R3 := R1 × R2 R3( A, R1.B, R2.B, C )‏ R1( A, B )‏ R2( B, C )‏ R3( A, R1.B, R2.B, C )‏
Constraints in Entity-Relationship Models
CPSC-310 Database Systems
CPSC-310 Database Systems
CPSC-608 Database Systems
The Entity-Relationship Model
CS 440 Database Management Systems
CPSC-608 Database Systems
Instructor: Zhe He Department of Computer Science
Database Models Relational Model
CPSC-310 Database Systems
CPSC-310 Database Systems
CPSC-310 Database Systems
CPSC-310 Database Systems
CPSC-310 Database Systems
The Relational Data Model
CPSC-608 Database Systems
CPSC-608 Database Systems
CS 405G Introduction to Database Systems
More SQL Extended Relational Algebra Outerjoins, Grouping/Aggregation
CPSC-608 Database Systems
CPSC-608 Database Systems
CMSC-461 Database Management Systems
Instructor: Zhe He Department of Computer Science
Select-From-Where Statements Multirelation Queries Subqueries
CS 405G: Introduction to Database Systems
Presentation transcript:

CPSC-310 Database Systems Professor Jianer Chen Room 315C HRBB Lecture #2 Source: modification of slides by Jeffrey Ullman of Stanford U.

Outline of Course Representing things by tables E-R model (Ch. 4) Good table structures Functional Dependencies (Ch. 3) Basic operations on relations Relational Algebra (Ch. 2) Storage management (Chs. 13-14) SQL languages in DDL/DML (Ch. 6) Query processing (Chs. 15-16) More on SQL (Chs. 7-9) Transition processing (Chs. 17-19)

The Entity/Relationship Model The E/R model is an intuitive (graphical) model used to sketch database designs, (where entity = object).

The Entity/Relationship Model The E/R model is an intuitive (graphical) model used to sketch database designs, (where entity = object). Properties of entities and how entities connect. Not how to operate on entities.

The Entity/Relationship Model The E/R model is an intuitive (graphical) model used to sketch database designs, (where entity = object). Properties of entities and how entities connect. Not how to operate on entities. E/R designs are given by pictures (entity/relationship diagrams).

The Entity/Relationship Model The E/R model is an intuitive (graphical) model used to sketch database designs, (where entity = object). Properties of entities and how entities connect. Not how to operate on entities. E/R designs are given by pictures (entity/relationship diagrams). It is in general straightforward to convert E/R designs to relational database designs.

Entity Sets Entity = “thing” or object.

Entity Sets Entity = “thing” or object. Entity set = collection of similar entities. Similar to a class in object-oriented languages.

Entity Sets Entity = “thing” or object. Entity set = collection of similar entities. Similar to a class in object-oriented languages. Attribute = property of (the entities of) an entity set.

Entity Sets Entity = “thing” or object. Entity set = collection of similar entities. Similar to a class in object-oriented languages. Attribute = property of (the entities of) an entity set. Attributes are of simple data types, e.g. integers or character strings.

E/R Diagrams In an entity-relationship diagram:

E/R Diagrams In an entity-relationship diagram: Entity set = rectangle.

E/R Diagrams In an entity-relationship diagram: Entity set = rectangle. Attribute = oval, with a line to the rectangle representing its entity set.

E/R Diagrams In an entity-relationship diagram: Example Entity set = rectangle. Attribute = oval, with a line to the rectangle representing its entity set. Example Entity set Beers has two attributes, name and manf (manufacturer)

E/R Diagrams In an entity-relationship diagram: Example Entity set = rectangle. Attribute = oval, with a line to the rectangle representing its entity set. Example Entity set Beers has two attributes, name and manf (manufacturer) Each Beers entity has values for these two attributes. e.g. (Bud, Anheuser-Busch)

E/R Diagrams In an entity-relationship diagram: Example Entity set = rectangle. Attribute = oval, with a line to the rectangle representing its entity set. Example Entity set Beers has two attributes, name and manf (manufacturer) Each Beers entity has values for these two attributes. e.g. (Bud, Anheuser-Busch) Beers name manf

Relationships A relationship connects some entity sets.

Relationships A relationship connects some entity sets. It is given by a diamond, with lines to each of the entity sets involved.

Relationships A relationship connects some entity sets. It is given by a diamond, with lines to each of the entity sets involved. Bars name license addr name manf Beers Drinkers name addr

Relationships A relationship connects some entity sets. It is given by a diamond, with lines to each of the entity sets involved. Bars sell some beers. Bars name license addr name manf Beers Drinkers name addr

Relationships A relationship connects some entity sets. It is given by a diamond, with lines to each of the entity sets involved. Bars sell some beers. Bars name license addr name manf Sells Beers Drinkers name addr

Relationships A relationship connects some entity sets. It is given by a diamond, with lines to each of the entity sets involved. Bars sell some beers. Bars name license addr name manf Sells Beers Likes Drinkers like some beers. Drinkers name addr

Relationships A relationship connects some entity sets. It is given by a diamond, with lines to each of the entity sets involved. Bars sell some beers. Bars name license addr name manf Sells Beers Frequents Likes Drinkers like some beers. Drinkers frequent some bars. Drinkers name addr

Relationship Set The current “value” of an entity set is the set of entities that belong to it. Example: the set of all bars in our database. The “value” of a relationship is a set of lists of currently related entities, one from each of the related entity sets. Bar Beer Joe’s Bar Bud Joe’s Bar Miller Sue’s Bar Bud Sue’s Bar Pete’s Ale Sue’s Bar Bud Lite For the relationship Sells, we might have a relationship set like:

Multiway Relationships Sometimes, we need a relationship that connects more than two entity sets.

Multiway Relationships Sometimes, we need a relationship that connects more than two entity sets. Example. Suppose that drinkers will only drink certain beers at certain bars.

Multiway Relationships Sometimes, we need a relationship that connects more than two entity sets. Example. Suppose that drinkers will only drink certain beers at certain bars. Our three binary relationships Likes, Sells, and Frequents do not allow us to make this distinction.

Multiway Relationships Sometimes, we need a relationship that connects more than two entity sets. Example. Suppose that drinkers will only drink certain beers at certain bars. Our three binary relationships Likes, Sells, and Frequents do not allow us to make this distinction. But a 3-way relationship would.

Multiway Relationships Sometimes, we need a relationship that connects more than two entity sets. Example. Suppose that drinkers will only drink certain beers at certain bars. Our three binary relationships Likes, Sells, and Frequents do not allow us to make this distinction. But a 3-way relationship would. name addr name Bars Beers Preferences manf license Drinkers name addr

Multiway Relationships Bar Drinker Beer Joe’s Bar Ann Miller Sue’s Bar Ann Bud Sue’s Bar Ann Pete’s Ale Joe’s Bar Bob Bud Joe’s Bar Bob Miller Joe’s Bar Cal Miller Sue’s Bar Cal Bud Lite

Multiplicity of Relationships

Multiplicity of Relationships We consider binary relationships, i.e., relationship between two entity sets.

Multiplicity of Relationships We consider binary relationships, i.e., relationship between two entity sets. In a many-many relationship, an entity of either set can be connected to many entities of the other set.

Multiplicity of Relationships We consider binary relationships, i.e., relationship between two entity sets. In a many-many relationship, an entity of either set can be connected to many entities of the other set. Example. a bar Sells many beers; a beer is sold by many bars.

Multiplicity of Relationships We consider binary relationships, i.e., relationship between two entity sets. In a many-many relationship, an entity of either set can be connected to many entities of the other set. Example. a bar Sells many beers; a beer is sold by many bars. Bars Beers A many-many relationship Sells

Multiplicity of Relationships We consider binary relationships, i.e., relationship between two entity sets. In a many-one relationship, an entity in one A of the entity sets is connected to at most one entity of the other entity set B, but an entity of B can be connected any number of entities of A.

Multiplicity of Relationships We consider binary relationships, i.e., relationship between two entity sets. In a many-one relationship, an entity in one A of the entity sets is connected to at most one entity of the other entity set B, but an entity of B can be connected any number of entities of A. Example. Favorite, from Drinkers to Beers is many-one.

Multiplicity of Relationships We consider binary relationships, i.e., relationship between two entity sets. In a many-one relationship, an entity in one A of the entity sets is connected to at most one entity of the other entity set B, but an entity of B can be connected any number of entities of A. Example. Favorite, from Drinkers to Beers is many-one. Drinkers Beers A many-one relationship Favorite

Multiplicity of Relationships We consider binary relationships, i.e., relationship between two entity sets. In a one-one relationship, each entity of either entity set is related to at most one entity of the other set.

Multiplicity of Relationships We consider binary relationships, i.e., relationship between two entity sets. In a one-one relationship, each entity of either entity set is related to at most one entity of the other set. Example. Relationship Best-seller between entity sets Manfs (manufacturer) and Beers.

Multiplicity of Relationships We consider binary relationships, i.e., relationship between two entity sets. In a one-one relationship, each entity of either entity set is related to at most one entity of the other set. Example. Relationship Best-seller between entity sets Manfs (manufacturer) and Beers. Manfs Beers A one-one relationship Best-seller

Representing “Multiplicity”

Representing “Multiplicity” Show a many-one relationship by an arrow entering the “one” side.

Representing “Multiplicity” Show a many-one relationship by an arrow entering the “one” side. Show a one-one relationship by arrows entering both entity sets.

Representing “Multiplicity” Show a many-one relationship by an arrow entering the “one” side. Show a one-one relationship by arrows entering both entity sets. Rounded arrow = “exactly one,” i.e., each entity of the first set is related to exactly one entity of the target set.

Representing “Multiplicity” Show a many-one relationship by an arrow entering the “one” side. Show a one-one relationship by arrows entering both entity sets. Rounded arrow = “exactly one,” i.e., each entity of the first set is related to exactly one entity of the target set. Drinkers Beers Likes Favorite

Example Consider Best-seller between Manfs and Beers.

Example Consider Best-seller between Manfs and Beers. Some beers are not the best-seller of any manufacturer, so a rounded arrow to Manfs would be inappropriate.

Example Consider Best-seller between Manfs and Beers. Some beers are not the best-seller of any manufacturer, so a rounded arrow to Manfs would be inappropriate. But a beer manufacturer has to have a best-seller.

Example Consider Best-seller between Manfs and Beers. Some beers are not the best-seller of any manufacturer, so a rounded arrow to Manfs would be inappropriate. But a beer manufacturer has to have a best-seller. Manfs Beers Best- seller

Attributes on Relationships Sometimes it is useful to attach an attribute to a relationship.

Attributes on Relationships Sometimes it is useful to attach an attribute to a relationship. Think of this attribute as a property of tuples in the relationship set.

Attributes on Relationships Sometimes it is useful to attach an attribute to a relationship. Think of this attribute as a property of tuples in the relationship set. Example. Price is a function of both the bar and the beer, not of one alone. Bars Beers Sells price

Attributes on Relationships Sometimes it is useful to attach an attribute to a relationship. Think of this attribute as a property of tuples in the relationship set. Example. Price is a function of both the bar and the beer, not of one alone. Equivalently, you can create an entity set representing values of the attribute, and make that entity set participate in the relationship. Bars Beers Sells price

Attributes on Relationships Sometimes it is useful to attach an attribute to a relationship. Think of this attribute as a property of tuples in the relationship set. Example. Price is a function of both the bar and the beer, not of one alone. Equivalently, you can create an entity set representing values of the attribute, and make that entity set participate in the relationship. Bars Sells Beers price Bars Beers Sells price Prices

Attributes on Relationships Sometimes it is useful to attach an attribute to a relationship. Think of this attribute as a property of tuples in the relationship set. Example. Price is a function of both the bar and the beer, not of one alone. Equivalently, you can create an entity set representing values of the attribute, and make that entity set participate in the relationship. Bars Sells Beers price Bars Beers Sells price Prices Note convention: arrow from multiway relationship means “all other entity sets together determine a unique one of these.”