CS 405G: Introduction to Database Systems

Slides:



Advertisements
Similar presentations
CS 405G: Introduction to Database Systems Instructor: Jinze Liu Fall 2009.
Advertisements

Database Management Systems Chapter 3 The Relational Data Model (I) Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
Chapter 3 : Relational Model
SQL Group Members: Shijun Shen Xia Tang Sixin Qiang.
Tallahassee, Florida, 2014 COP4710 Database Systems Relational Model Fall 2014.
CSCI 305 – Fall 2013 The Entity-Relationship Model Based on Slides by Prof. Brian King.
1 Convert E/R to Relation May 18, Entity Set -> Relation Relation: Beers(name, manf) Beers name manf.
Databases : Relational Model 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman distributes.
Entity-Relationship Model
Chapter 4 Notes. Entity-Relationship Model E/R Diagrams Weak Entity Sets Converting E/R Diagrams to Relations.
1 Relational Model and Translating ER into Relational.
The Relational Data Model Database Model (E/R) Relational Schema Physical storage Diagrams (E/R) Tables: row names: attributes rows: tuples Complex file.
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.
From E/R Diagrams to Relations. The Relational Data Model Database Model (E/R) Relational Schema Physical storage Diagrams (E/R) Tables: row names: attributes.
Fall 2001Arthur Keller – CS 1803–1 Schedule Today Oct. 2 (T) Relational Model. u Read Sections Assignment 1 due. Personal Letter of Introduction.
CS 405G: Introduction to Database Systems Lecture 4: Relational Model Instructor: Chen Qian.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations Source: slides by Jeffrey Ullman.
Winter 2002Arthur Keller – CS 1803–1 Schedule Today: Jan. 10 (TH) u Relational Model, Functional Dependencies. u Read Sections Jan. 15 (T) u Normal.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations.
1 Entity-Relationship Model E/R Diagrams Weak Entity Sets Converting E/R Diagrams to Relations.
Data Modeling Translating E-R Diagrams to Relations
12/2/2015CPSC , CPSC , Lecture 41 Relational Model.
CS 405G: Introduction to Database Systems Lecture 5: Logical Design by Relational Model Instructor: Chen Qian.
Databases 1 Fifth lecture. Entity-Relationship Model Diagrams Class hierarchies Weak entity sets From E/R diagrams to Relations 2.
Instructor: Jinze Liu Fall Phases of Database Design u Conceptual design begins with the collection of requirements and results needed from the.
Santa Clara UniversityHolliday – COEN 1783–1 Today’s Topic Today: u Relational Model, Functional Dependencies. u Read Sections Next time u Normal.
CPSC 603 Database Systems Lecturer: Laurie Webster II, M.S.S.E., M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 4 Introduction to a First Course in Database Systems.
Entity-Relationship Model E/R Diagrams Converting E/R Diagrams to Relations.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations Functional Dependencies.
CS 405G: Introduction to Database Systems Relations.
Jennifer Widom Relational Databases The Relational Model.
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.
Introduction to Database Systems, CS420
Select-From-Where Statements Multirelation Queries Subqueries
Introduction to Databases
Entity-Relationship Model
Modeling Constraints Extracting constraints is what modeling is all about. But how do we express them? Examples: Keys: social security number uniquely.
Schedule Today: Jan. 28 (Mon) Jan. 30 (Wed) Next Week Assignments !!
CPSC-310 Database Systems
Computational Biology
The Relational Model.
COP4710 Database Systems Relational Model.
Cushing, Keller, UlmanJudy Cushing
Introduction to Database Systems, CS420
Introduction to Database Systems, CS420
CPSC-310 Database Systems
CPSC-608 Database Systems
The Entity-Relationship Model
CS 440 Database Management Systems
Instructor: Zhe He Department of Computer Science
Database Models Relational Model
CPSC-310 Database Systems
CPSC-310 Database Systems
Relational Databases The Relational Model.
Relational Databases The Relational Model.
2018, Fall Pusan National University Ki-Joune Li
The Relational Data Model
EECS 647: Introduction to Database Systems
CS4433 Database Systems Relational Model.
CS 405G Introduction to Database Systems
CS 505: Intermediate Topics to Database Systems
CPSC-608 Database Systems
CE223 Database Systems Introduction
CS 405G: Introduction to Database Systems
Instructor: Zhe He Department of Computer Science
Select-From-Where Statements Multirelation Queries Subqueries
2019, Fall Pusan National University Ki-Joune Li
Presentation transcript:

CS 405G: Introduction to Database Systems Relations 1

Topics Next Case study on ER Model Conversion of ER models to Schemas Reading Assignment Chapter 5.1, 5.2 10/28/2019 10/28/2019 2 2 2

ER Case study Design a database representing cities, counties, and states For states, record name and capital (city) For counties, record name, area, and location (state) For cities, record name, population, and location (county and state) Assume the following: Names of states are unique Names of counties are only unique within a state Names of cities are only unique within a county A city is always located in a single county A county is always located in a single state 10/28/2019 10/28/2019 3 3

Case study : first design County area information is repeated for every city in the county Redundancy is bad. What else? State capital should really be a city Should “reference” entities through explicit relationships name name In Cities States population capital county_name county_area 10/28/2019 10/28/2019 4 4 4

Case study : second design Technically, nothing in this design could prevent a city in state X from being the capital of another state Y, but oh well… name Cities population In IsCapitalOf name In Counties States name area 10/28/2019 10/28/2019 5 5 5

Review A data model is a group of concepts for describing data. What are the two terms used by ER model to describe a miniworld? Entity Relationship What makes a good database design Student (sid: string, name: string, login: string, age: integer, gpa:real) 1010111101 10/28/2019 10/28/2019 6 6 6

Database Design 10/28/2019 10/28/2019 7 7 7

A Relation is a Table name manf Winterbrew Pete’s Bud Lite Anheuser-Busch Beers Attributes (column headers) Tuples (rows)

Schemas Relation schema = relation name + attributes, in order (+ types of attributes). Example: Beers(name, manf) or Beers(name: string, manf: string) Database = collection of relations. Database schema = set of all relation schemas in the database.

Why Relations? Very simple model. Often matches how we think about data. Abstract model that underlies SQL, the most important database language today. But SQL uses bags, while the relational model is a set-based model.

From E/R Diagrams to Relations Entity sets become relations with the same set of attributes. Relationships become relations whose attributes are only: The keys of the connected entity sets. Attributes of the relationship itself.

Entity Set -> Relation Relation: Beers(name, manf) name manf Beers

Relationship -> Relation name name addr manf Drinkers Likes Likes(drinker, beer) Beers Married husband wife Married(husband, wife) Buddies 1 2 Buddies(name1, name2) Favorite Favorite(drinker, beer)

Combining Relations It is OK to combine the relation for an entity-set E with the relation R for a many-one relationship from E to another entity set. Example: Drinkers(name, addr) and Favorite(drinker, beer) combine to make Drinker1(name, addr, favBeer).

Risk with Many-Many Relationships Combining Drinkers with Likes would be a mistake. It leads to redundancy, as: name addr beer Sally 123 Maple Bud Sally 123 Maple Miller Redundancy

Handling Weak Entity Sets Relation for a weak entity set must include attributes for its complete key (including those belonging to other entity sets), as well as its own, nonkey attributes. A supporting (double-diamond) relationship is redundant and yields no relation.

Example name name Logins At Hosts time

Example name name Logins At Hosts time Hosts(hostName) Logins(loginName, hostName, time) At(loginName, hostName, hostName2) At becomes part of Logins Must be the same

A (Slightly) Formal Definition A database is a collection of relations (or tables) Each relation is identified by a name and a list of attributes (or columns) Each attribute has a name and a domain (or type) Set-valued attributes not allowed 19 19 19

Schema versus instance Schema (metadata) Specification of how data is to be structured logically Defined at set-up Rarely changes Instance Content Changes rapidly, but always conforms to the schema Compare to type and objects of type in a programming language 10/28/2019 10/28/2019 20 20 20

Example Schema Instance Student (SID integer, name string, age integer, GPA float) Course (CID string, title string) Enroll (SID integer, CID integer) Instance { h142, Bart, 10, 2.3i, h123, Milhouse, 10, 3.1i, ...} { hCPS116, Intro. to Database Systemsi, ...} { h142, CPS116i, h142, CPS114i, ...} 10/28/2019 10/28/2019 21 21 21