CS 505: Intermediate Topics 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.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
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.
1 Relational Model and Translating ER into Relational.
1 Translation of ER-diagram into Relational Schema Prof. Sin-Min Lee Department of Computer Science.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
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 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
The Relational Model Lecture 3 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) From ER to Relational.
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.
Database Systems Relational Model Concepts Toqir Ahmad Rana Database Management Systems 1 Lecture 17.
The Relational Model These slides are based on the slides of your text book.
Relational Data Model, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 The Relational Model Chapter 3.
The Relational Model. Review Why use a DBMS? OS provides RAM and disk.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations.
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.
Data Modeling Translating E-R Diagrams to Relations
CMPT 258 Database Systems The Relationship Model PartII (Chapter 3)
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.
ICS 421 Spring 2010 Relational Model & Normal Forms Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 1/19/20101Lipyeow.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
CS 405G: Introduction to Database Systems Relations.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints تنبيه.
ER Diagrams and Relational Model CS 174a (Winter 2015)
Introduction to Database Systems, CS420
Entity-Relationship Model
COP Introduction to Database Structures
COP4710 Database Systems Relational Model.
Cushing, Keller, UlmanJudy Cushing
Entity-Relationship Model
CPSC-310 Database Systems
Constraints AND Examples
Instructor: Zhe He Department of Computer Science
Translation of ER-diagram into Relational Schema
Relational Integrity Constraints
CPSC-310 Database Systems
The Relational Model Content based on Chapter 3
The Relational Model Relational Data Model
DATABASE SYSTEM.
Translation of ER-diagram into Relational Schema
The Relational Model The slides for this text are organized into chapters. This lecture covers Chapter 3. Chapter 1: Introduction to Database Systems Chapter.
The Relational Data Model
EECS 647: Introduction to Database Systems
CS 405G Introduction to Database Systems
Constraints AND Examples
The Relational Model Content based on Chapter 3
The Relational Model Content based on Chapter 3
CS 405G: Introduction to Database Systems
CS 405G: Introduction to Database Systems
CS 405G: Introduction to Database Systems
Presentation transcript:

CS 505: Intermediate Topics to Database Systems Instructor: Jinze Liu Fall 2008 1

Phases of Database Design Conceptual design begins with the collection of requirements and results needed from the database (ER Diag.) Logical schema is a description of the structure of the database (Relational, Network, etc.) Physical schema is a description of the implementation (programs, tables, dictionaries, catalogs

Models A data model is a collection of objects that can be used to represent a set of data and operations to manipulate the data Conceptual models are tools for representing reality at a very high-level of abstraction Logical models are data descriptions that can be processed by computers

Conceptual model: Entity-Relationship Diagrams Entities represent classes of real-world objects. Person, Students, Projects, Courses are entities of a University database Relationships represent interactions between two or more entities

Example: Every employee works in at least one project Every project has employees working on it.

Higher-Order Relationships A relationship may involve more than two entities

Recursive relationships Relationships could be mapped from one entity to itself

Attributes Attributes represent elementary properties of the entities or relationships. The stored data will be kept as values of the attributes

Case study : first design name name In Cities States population capital county_name county_area 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 4/27/2019 4/27/2019 11 11 11

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

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 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 4/27/2019 4/27/2019 23 23 23

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 4/27/2019 4/27/2019 24 24 24

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, ...} 4/27/2019 4/27/2019 25 25 25

Relational Integrity Constraints Constraints are conditions that must hold on all valid relation instances. There are four main types of constraints: Domain constraints The value of a attribute must come from its domain Key constraints Entity integrity constraints Referential integrity constraints 4/27/2019 4/27/2019 26 26 26

Primary Key Constraints A set of fields is a candidate key for a relation if : 1. No two distinct tuples can have same values in all key fields, and 2. This is not true for any subset of the key. Part 2 false? A superkey. If there’s >1 key for a relation, one of the keys is chosen (by DBA) to be the primary key. E.g., given a schema Student(sid: string, name: string, gpa: float) we have: sid is a key for Students. (What about name?) The set {sid, gpa} is a superkey. 4/27/2019 Jinze Liu @ University of Kentucky 27 6 27

Key Example CAR (licence_num: string, Engine_serial_num: string, make: string, model: string, year: integer) What is the candidate key(s) Which one you may use as a primary key What are the super keys 4/27/2019 4/27/2019 28 28 28

Entity Integrity Entity Integrity: The primary key attributes PK of each relation schema R in S cannot have null values in any tuple of r(R). Other attributes of R may be similarly constrained to disallow null values, even though they are not members of the primary key. 4/27/2019 4/27/2019 29 29 29

Foreign Keys, Referential Integrity Foreign key : Set of fields in one relation that is used to `refer’ to a tuple in another relation. (Must correspond to primary key of the second relation.) Like a `logical pointer’. E.g. sid is a foreign key referring to Students: Student(sid: string, name: string, gpa: float) Enrolled(sid: string, cid: string, grade: string) If all foreign key constraints are enforced, referential integrity is achieved, i.e., no dangling references. Can you name a data model w/o referential integrity? Links in HTML! 4/27/2019 Jinze Liu @ University of Kentucky 30 7 30

Jinze Liu @ University of Kentucky Foreign Keys Only students listed in the Students relation should be allowed to enroll for courses. Enrolled Students Or, use NULL as the value for the foreign key in the referencing tuple when the referenced tuple does not exist 4/27/2019 Jinze Liu @ University of Kentucky 31 7 31

Other Types of Constraints Semantic Integrity Constraints: based on application semantics and cannot be expressed by the model per se e.g., “the max. no. of hours per employee for all projects he or she works on is 56 hrs per week” A constraint specification language may have to be used to express these SQL-99 allows triggers and ASSERTIONS to allow for some of these 4/27/2019 4/27/2019 32 32 32