Relational Model CS 157A Prof. Sin-Min Lee By Truc Truong.

Slides:



Advertisements
Similar presentations
Logical DB Design: ER to Relational Entity sets to tables. Employees ssn name lot CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER, PRIMARY.
Advertisements

Chapter 10: Designing Databases
High-Level Database Models Spring 2011 Instructor: Hassan Khosravi.
Relational Model Table = relation. Column headers = attributes. Row = tuple Beers Relation schema = name(attributes) + other structure info., e.g., keys,
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.
Relational Model (CB Chapter 4) CPSC 356 Database Ellen Walker Hiram College.
SQL This presentation will cover: A Brief History of DBMS View in database MySQL installation.
Feb 4: Recap of Jan 30 class Data Models: E-R and Relational (and some others of mostly historical interest) We examined the E-R model –Entities, Relationships,
Functional Dependencies - Example
Design Principles: Faithfulness
Design Principles: Faithfulness
Monash University Week 7 Data Modelling Relational Database Theory IMS1907 Database Systems.
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.
Additional ODL Concepts OO Model to Relational Model Object-Relational Design OO vs OR.
Movies length titleyearfilmType Voices isa Cartoons isa MurderMystery weapon toStar Our Movie Example.
A four-way Relationship
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.
The Entity-Relationship Data Model
Other Data Models. Text New edition (DBS the complete book): Chapter 4 Old edition (First course in DBS): –Section 2.1 –Section –Section 2.4.1,
Fall 2001Arthur Keller – CS 1803–1 Schedule Today Oct. 2 (T) Relational Model. u Read Sections Assignment 1 due. Personal Letter of Introduction.
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 Entity-Relationship Data Model Chapter 2 (Database Design)
1 Relational Data Model CS 157B Nidhi Patel. 2 What is a Data Model? A notation for describing data or information A notation for describing data or information.
1 Lecture 4: Database Modeling (end) The Relational Data Model April 8, 2002.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
Module Title? DBMS E-R Model to Relational Model.
Chapter 4 The Relational Model.
Chapter 4 Rational data model. Chapter 5 Rational data model Chapter 4 Rational data model.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model  Vendors: IBM, Informix, Microsoft, Oracle, Sybase  Recent.
Database Management COP4540, SCS, FIU Relational Model Chapter 7.
Database Management System Lecture 4 The Relational Database Model- Introduction, Relational Database Concepts.
SQL, Data Storage Technologies, and Web-Data Integration Week 2.
Conversion E/R to Relational CIS 4301 Lecture Notes Lecture 6 - 1/31/2006.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
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.
Relational Data Model Ch. 7.1 – 7.3 John Ortiz Lecture 3Relational Data Model2 Why Study Relational Model?  Most widely used model.  Vendors: IBM,
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
EXAMPLE. Subclasses and Superclasses Entity type may have sub-grouping that need to be represented explicitly. –Example: Employee may grouped into.
© D. Wong Ch. 2 Entity-Relationship Data Model (continue)  Data models  Entity-Relationship diagrams  Design Principles  Modeling of constraints.
Entity-Relationship Model
UNIT_2 1 DATABASE MANAGEMENT SYSTEM[DBMS] [Unit: 2] Prepared By Lavlesh Pandit SPCE MCA, Visnagar.
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.
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
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.
The Entity-Relationship Model CIS 4301 Lecture Notes 1/12/2006.
CS 405G: Introduction to Database Systems Relations.
Jennifer Widom Relational Databases The Relational Model.
CPSC 603 Database Systems Lecturer: Laurie Webster II, M.S.S.E., M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 5 Introduction to a First Course in Database Systems.
The Relational Model of Data Prof. Yin-Fu Huang CSIE, NYUST Chapter 2.
1 10 Systems Analysis and Design in a Changing World, 2 nd Edition, Satzinger, Jackson, & Burd Chapter 10 Designing Databases.
© D. Wong Ch. 3 (part 1)  Relational Model basics  From E/R diagram to Relations.
Chapter 3 The Relational Model. Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. “Legacy.
High-level Database Models Prof. Yin-Fu Huang CSIE, NYUST Chapter 4.
Modeling: Entity-Relationship Diagrams
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
1 Database Modeling (Semantic data modeling) ER Data Model –A high-level conceptual data model –Proposed by P. Chen (1976) –Widely used in DB design process.
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.
The Entity-Relationship Diagram for Data Modeling
ER Diagrams and Relational Model CS 174a (Winter 2015)
Logical Database Design and the Rational Model
Modeling Constraints Extracting constraints is what modeling is all about. But how do we express them? Examples: Keys: social security number uniquely.
COP Introduction to Database Structures
Appendix D: Network Model
Transforming E/R to Relational Model.
SQL This presentation will cover: View in database MySQL installation
ITEC 3220A Using and Designing Database Systems
Lecture 5: The Relational Data Model
Presentation transcript:

Relational Model CS 157A Prof. Sin-Min Lee By Truc Truong

What is Relational Model?   Relational model is most widely used data model for commercial data-processing. The reason it’s used so much is, because it’s simple and easy to maintain.   The model is based on a collection of tables. Users of the database can create tables, insert new tables or modify existing tables. There are several languages for database programming. SQL, Oracle, etc.

History of Relational Modeling  Introduced by Ted Codd in 1970  Ted Codd was an IBM Researcher  Laid the foundation for database theory  Many database concepts & products based on his model

Relational Model Basic The relational model gives us a single way to represent data: as a two- dimensional table called a relation.  Attributes  Schemas  Tuples  Domains  Equivalent Representations of a Relation

Attributes Attribute TitleYearLength Star Wars Might Ducks Wayne’s World Attributes of a relation serve as names for the columns of the relation. Usually, an attribute describes the meaning of entries in the column below. Table = relation. Column headers = attributes.

Schemas  The name of a relation and the set of attributes for a relation is called a schema.  We show the schema for the relation with the relation name followed by a parenthesized list of its attributes.  Relation schema = name(attributes) + other structure info., e.g., keys, other constraints.  Order of attributes is arbitrary, but in practice we need to assume the (standard) order given in the relation schema.  Relational database schema = collection of relation schemas.  So the schema for previous slide is Movies (title, year, length) Movies (title, year, length)

Database Schema  DataBase Schema Logical View of the DatabaseLogical View of the Database  Database Instance A view of data in database at anytime.A view of data in database at anytime.  Relation Schema Corresponds to the programming language concept of type definitionCorresponds to the programming language concept of type definition E.g. JavaE.g. Java  String movie = “Spiderman”;  Relation Instance Corresponds to the programming-language concept of the value of a variable E.g. Java   String movie = “Spiderman”;

Tuples Tuple TitleYearLength Star Wars Might Ducks Wayne’s World  The rows of a relation, other than the header row containing The attribute names are called tuples.  A tuple has one component for each attribute of the relation.

Domains  Each attribute of a relation is associated with a particular elementary type called domain.  The components of any tuple of the relation must have, in each component, a value that belongs to the domain of the corresponding column.  Example: with title string is associatedwith title string is associated with year integer is associatedwith year integer is associated

Equivalent Representations of a Relation  Schemas are sets of attributes (not lists).  Tuples are sets of components (not lists).  Instances are sets of tuples (not lists)   After permutation of rows and columns the relations remains the same! (permute values and attributes)

Equivalent Representations of a Relation cont.  Formal notion of a tuple= a function {attributes}  {values} title  Star Warstitle  Star Wars year  1977year  1977 length  121length  121 filmType  colorfilmType  color  (Star Wars, 1977, 121,color) and (1977, 121,color, Star Wars) are the same object.

TitleYearLength Star Wars Mighty Ducks Wayne’s World YearLengthTitle Star Wars Mighty Ducks Wayne’s World Original Relation Modified Relation

A 1 A 2 A 3... A n a 1 a 2 a 3 a n b 1 b 2 a 3 c n a 1 c 2 b 3 b n. x 1 v 2 d 3 w n Relational Data Model: summary  Set theoretic  Domain — set of values  like a data type  Cartesian product (or product)  D1  D2 ...  Dn  n-tuples (V1,V2,...,Vn)  s.t., V1  D1, V2  D2,...,Vn  Dn Relation=subset of cartesian product of one or more domainsRelation=subset of cartesian product of one or more domains  FINITE only; empty set allowed Tuples = members of a relation inst.Tuples = members of a relation inst. Arity = number of domainsArity = number of domains Components = values in a tupleComponents = values in a tuple Domains — corresp. with attributesDomains — corresp. with attributes Cardinality = number of tuplesCardinality = number of tuples Relation as table Rows = tuples Columns = components Names of columns = attributes Relation name + set of attribute names= schema REL (A 1,A 2,...,A n ) Arity CardinalityCardinality Attributes Component Tuple

Schema versus Instance  DB instances change continuously (e.g., movies are added, deleted, changed,…)  The schema is stable (attributes change almost never)  A RDB instance is the set of tuples that are ‘now’ in the DB  When designing the DB only the schema is important (=the structure of the data/DB)  We only imagine typical instances to help us with the design  Intentional level: schema  Extensional level: instances

E/R Diagrams to Relational Designs Creation of a DB:  Design phase (on “paper”, which information, relationships, constraints, …)  Implementation phase (real RDBMS)  It is “easier” to start from ODL or E/R and later convert to RM RM has only one concept (relation)RM has only one concept (relation) E/R and ODL have complementary concepts and are more flexible (constraints, …)E/R and ODL have complementary concepts and are more flexible (constraints, …)  Converting E/R design to a relational database schema: Turn each entity set into a relation with the same set of attributesTurn each entity set into a relation with the same set of attributes Replace a relationship by a relation whose attributes are the keys for the connected entity set.Replace a relationship by a relation whose attributes are the keys for the connected entity set. *Weak entity sets cannot be translated straightforwardly to relations *”Isa” relationships and subclasses require careful treatment.

Relational Design cont.  Design in ODL or E/R (schema+constraints)  implementation in a RDBMS  Simplest approach (not always best): convert each ODL class or E/R entity set to a relation and each relationship to a relation. Class/Entity Set  Relation Relationship  Relation

From Entity Sets to Relations  An entity set that is not weak, is translated into a relation with the same name and attributes.  E.g., Movie(title, year, length, filmType) Star(name, address) or Star(name, street, city) title year lengthname address name address Studios StarMovies Owns Stars-in filmType

From E/R Relationships to Relations E/R relationships are also translated to relations: 1. For each entity set involved in R, take key attribute(s) as part of schema 2. If the relationship has attributes, add them to the schema  If an entity set appears more than once in a relationship, rename its attributes to avoid doubles and for clarity!  E.g., Owns(title, year, studioName) title year lengthname address name address StudiosStarMovies Owns Stars-in filmType

Relationships to Relation cont.  If an entity set appears more than once in a relationship, rename its attributes to avoid doubles! name  E.g., Contracts(title,year,starName, studioOfStar,producingStudio) Star Movies Contracts Studio Producing studio Studio of star

Handling Weak Entity Set If there is a weak entity sets W we do the following differently:  Attributes of W plus key attributes of other entity sets that contribute to the key of W (double-diamond; many-one).  Any relationship in which W appears must use as a key for W all of its attributes including those of the other entity sets that contribute to W’s key  Double-diamond relationships from W to another entity set do not need to be converted (this information is already in the relation for W).

Studios(name, address) Crews(number,studioName) Unit-of(number,studioName,name)  Unit-of(number,name) are the same (many-one!) are the same (many-one!) (Disney crew #3, Disney)  (3, Disney, Disney) name Studios number address Unit-ofCrews

Contracts(starName, studioName, title, year, salary) Relations for Movie-of, Star-of and Studio-of are superfluous… Movies Studios StarsContracts Star-of salary titleyear name length address filmType StarOf ContractsMovieOf Studio Of Stars

Converting Subclass Structures to Relations Differences between E/R and ODL:  In ODL: an object belongs to exactly one class. It inherits properties from superclass.  In E/R: an object may belong to several entity sets related by isa.

Structures to Relations cont.  Every subclass has its own relation  It has all properties of this subclass including inherited properties  E.g., Movie(title,year,length,filmType,studioName,starName)Cartoon(title,year,length,filmType,StudioName,starName, voice) MurderMystery(title,year,length,filmType,StudioName,starN ame,weapon)MurderMystery(title,year,length,filmType,StudioName,starN ame,weapon) Cartoon-MurderMystery(title,year,length,filmType,Cartoon-MurderMystery(title,year,length,filmType, StudioName,starName,voice, weapon)

An Object-Oriented Approach A hierarchy is populated by entities related by isa’s.  No relation is created for the isa relationship.  For each entity set, a separate relation with its own attributes plus key attributes of related attribute sets. Bugs Bunny title length Movies Cartoons isa year filmType Voices Murder- Mysteries isa weapon

Differences between E/R and ODL:  In ODL: all properties of an object together in one relation; we have to search 4 relations to find a movie object! Movie(title,year,length,filmType,studioName,starName )  Cartoon(title,year,length,filmType,StudioName, starName,voice)  MurderMystery(title,year,length,filmType,StudioNam e,starName,weapon)  Cartoon-MurderMystery(title,year,length,filmType, StudioName,starName,voice,weapon)

Differences between E/R and ODL:  In E/R: a key of an entity is repeated once for every entity set and relationship it belongs to (scattered information).

Using Null Values to Combine Relations  ODL: Information of a hierarchy can be given in one relation  NULL = “there is no appropriate value for this attribute”  E.g., Movie(title,year,length,filmType,StudioName, starName,voice, weapon)

References  Jeff Ullman and Jennifer Widom, A First Course in Database systems. 2nd edition, Prentice Hall. Jennifer WidomJennifer Widom  Prof. Lee “Relation Model” Presentation  science.kennesaw.edu/~mguimara/8 080/ch3_4.ppt  cture2.ppt