Relational Data Model Ch. 7.1 – 7.3 John Ortiz Lecture 3Relational Data Model2 Why Study Relational Model?  Most widely used model.  Vendors: IBM,

Slides:



Advertisements
Similar presentations
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Advertisements

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.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke. Edited by Keith Shomper, The Relational Model Chapter 3.
The Relational Model Class 2 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) (From ER to Relational)
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 28 Database Systems I The Relational Data Model.
D ATABASE S YSTEMS I T HE R ELATIONAL D ATA M ODEL.
The Relational Model Ramakrishnan & Gehrke Chapter 3.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
The Relational Model Ramakrishnan & Gehrke, Chap. 3.
The Relational Model 198:541 Rutgers University. Why Study the Relational Model?  Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle,
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 Data Modeling Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E) 1.
CS 380 Introduction to Database Systems (Chapter 5: The Relational Data Model and Relational Database Constraints)
1 The Relational Model Chapter 3. 2 Objectives  Representing data using the relational model.  Expressing integrity constraints on data.  Creating,
The Relational Model These slides are based on the slides of your text book.
The Relational Model Chapter 3
Data Models Amandeep Kaur Lecturer GPC Khunimajra Call at
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 Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3 Modified by Donghui Zhang.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model  Vendors: IBM, Informix, Microsoft, Oracle, Sybase  Recent.
1 The Relational Model Instructor: Mohamed Eltabakh
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 5 The Relational Data Model.
10/9/20151 The Relational Data Model TCU Database Systems Last update: September 2004 Reference: Elmasri 4 th edition, chapter 5.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc.
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.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
The Relational Model Content based on Chapter 3 Database Management Systems, (Third Edition), by Raghu Ramakrishnan and Johannes Gehrke. McGraw Hill, 2003.
1 CS 430 Database Theory Winter 2005 Lecture 4: Relational Model.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
CMPT 258 Database Systems The Relationship Model PartII (Chapter 3)
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 3 The Relational Model.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
The Relational Model Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Database Management Systems 1 Raghu Ramakrishnan The Relational Model Chapter 3 Instructor: Jianping Fan.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Chapter 3 The Relational Model. Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. “Legacy.
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.
Database Management Systems 1 Raghu Ramakrishnan The Relational Model Chapter 3 Instructor: Xin Zhang.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
COP Introduction to Database Structures
Translation of ER-diagram into Relational Schema
Instructor: Mohamed Eltabakh
The Relational Model Content based on Chapter 3
The Relational Model Chapter 3
The Relational Model Relational Data Model
The Relational Model Chapter 3
Database Systems The Basic (Flat) Relational Model
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 Model Chapter 3
Instructor: Mohamed Eltabakh
The Relational Model Content based on Chapter 3
The Relational Model Content based on Chapter 3
Presentation transcript:

Relational Data Model Ch. 7.1 – 7.3 John Ortiz

Lecture 3Relational Data Model2 Why Study Relational Model?  Most widely used model.  Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc.  “Legacy systems” in older models  E.G., IBM’s IMS (hierarchical model)  Recent competitor: object-oriented model  ObjectStore, Versant, Ontos, O2  A synthesis emerging: object-relational model  Informix UDS, UniSQL, Oracle, DB2

Lecture 3Relational Data Model3 Anatomy of a Relation  Each relation is a table with a name.  An attribute is a column heading.  The heading is the schema of the relation Students(SSN, Name, Age, GPA) Students Relation name Attribute name Column Tuple

Lecture 3Relational Data Model4 Domain of an Attribute  The domain of an attribute A, denoted by Dom(A), is the set of values that the attribute can take.  A domain is usually represented by a type. E.g.,  SID char(4)  Name varchar(30) --- character string of variable length up to 30  Age number --- a number

Lecture 3Relational Data Model5 Tuples  A tuple of a relation is a row in its table.  If t is a tuple of a relation R and A is an attribute of R, we use t[A] to represent the value of t under A in R. Example: If t is the second tuple in Students t[Name] = ‘Mary Day’ t[Age] = 18, t[Name, Age] = (‘Mary Day’, 18)

Lecture 3Relational Data Model6 Schema and Instance  A relation schema, denoted by R(A1, A2, …, An), consists of the relation name R and a list of attributes A1, …, An.  R.A denotes attribute A of R.  # of attributes = degree  A relation instance (state) of a relation schema R(A1, …, An), denoted by r(R), is a set of tuples in the table of R at some instance of time.  # of tuples = cardinality

Lecture 3Relational Data Model7 Schema & Instance Update  The schema of a relation may change (e.g., adding, deleting, renaming attributes and deleting a table schema) but it is infrequent  The state of a relation may also change (e.g., inserting or deleting a tuple, and changing an attribute value in a tuple) & it is frequent  A schema may have different states at different times.

Lecture 3Relational Data Model8 Relational Database  A relational database schema is a set of relation schemas S={R1, …, Rm}.  A relational database is a set of relations DB(S)={r(R1), …, r(Rm)}.  A database state is a set of relation instances at some instance of time.  In addition, a relational database must satisfy a number of constraints (more to come later).

Lecture 3Relational Data Model9 A University Database see p. 204, Fig. 7.5 StudentsSections Courses Departments

Lecture 3Relational Data Model10 Constraints of Relational DB  Relations must satisfy the following constraints.  Domain (1NF) Constraint.  Access-by-Content Constraint.  Key (Unique Tuple) Constraint.  Entity Integrity Constraint.  Referential Integrity Constraint.  Integrity constraints are enforced by the RDBMS.

Lecture 3Relational Data Model11 Domain Constraint  Also known as the First Normal Form (1NF): Attributes can only take atomic values (I.e., set values are not allowed).  How to handle multivalued attributes?  Use multiple tuples, one per value  Use multiple columns, one per value  Use separate tables  What problems does these solutions have?

Lecture 3Relational Data Model12 Handle Multi-Valued Attributes Employees Multiple Values: Use Multiple Tuples:

Lecture 3Relational Data Model13 Handle Multi-Valued Attributes Employees Dependents Use Multiple Columns: Use Separate Relations:

Lecture 3Relational Data Model14 Non-1NF Relations*  Tables allowing multivalued attributes are called non-first normal form (NFNF) tables which are supported by some non-standard relational database systems.  Some database models permit multi-valued attributes. For example, most object-oriented databases do.

Lecture 3Relational Data Model15 Access-by-Content Constraint  A tuple is retrieved only by values of its attributes, i.e., the order of tuples is not important.  This is because a relation is a set of tuples.  Although the order of tuples is insignificant for query formulation, it is significant for query evaluation.

Lecture 3Relational Data Model16 Superkey  A superkey of a relation is a set of attributes whose values uniquely identify the tuples of the relation.  Every relation has at least one superkey (default is all attributes together?).  Any superset of a superkey is a superkey.  From a state of a relation, we may determine that a set of attributes is not a superkey, but can not determine that a set of attributes is a superkey.

Lecture 3Relational Data Model17 Superkey Example  Find all superkeys of the Students relation. Students R  With the only state of R, is A a superkey? What about {A, B}?

Lecture 3Relational Data Model18 Candidate Key  A candidate key of a relation is a set of attributes of the relation such that  it is a superkey, and  none of its proper subsets is a superkey.  Find all candidate keys in Students relation.  Is it true that every relation has at least candidate key? Why?  Can candidate keys be found from a state?  If AB is a candidate key of a relation, can A also be a candidate key? What is ABC called?

Lecture 3Relational Data Model19 Primary Key  A primary key of a relation is a candidate key designated (with an underline) by a database designer.  Often chosen at the time of schema design, & once specified to DBMS, it cannot be changed.  Better be the smallest candidate key for improvement of both storage and query processing efficiencies.  What should be the primary key of Students?

Lecture 3Relational Data Model20 Key Constraint  Every relation must have a primary key.  Why is key constraint needed?  Every tuple has a different primary key value.  Only the primary key values need to be checked for identifying duplicate when new tuples are inserted (index is often used).  Primary key values can be referenced from within other relations

Lecture 3Relational Data Model21 Entity Integrity Constraint  A null value is a special value that is  unknown,  yet to be assigned, or  inapplicable.  Entity Integrity Constraint: No primary key values can be null.  Why?

Lecture 3Relational Data Model22 Foreign Key  A foreign key in relation R1 referencing relation R2 is a set of attributes FK of R1, such that,  FK is compatible with a candidate (or primary) key PK of R2 (with same number of attributes and compatible domains); and  for every tuple t1 in R1, either there exists a tuple t2 in R2 such that t1[FK] = t2[PK] or t1[FK] = null.  Foreign keys need to be explicitly defined.

Lecture 3Relational Data Model23 Foreign Key Example EmployeesDepartments  DName of Employees is a foreign key referencing Name of Departments  A foreign key may reference its own relation. Employee(EID, Name, Age, Dept, ManegerID)

Lecture 3Relational Data Model24 Referential Integrity Constraint  Referential Integrity Constraint: No relation can contain unmatched foreign key values.  Using foreign keys in a relation to reference primary keys of other relations is the only way in the relational data model to establish relationships among different relations.

Lecture 3Relational Data Model25 Update Operations  Insert  Can violate any of the 4 previous constraints – what were they again?  1 solution: reject the insert  Delete  Can only violate referential integrity – why?  3 solutions: reject deletion, propagate deletion, modify referencing attributes  Modify  Can violate any of the 4 previous constraints

Lecture 3Relational Data Model26 Relational Model: Summary  A tabular representation of data.  Simple and intuitive, currently the most widely used.  Integrity constraints can be specified by the DBA, based on application semantics. DBMS checks for violations.  Two important ICs for primary and foreign keys  In addition, we always have domain constraints.

Lecture 3Relational Data Model27 Relational Model: Summary  ICs are based upon the semantics of the real- world enterprise that is being described in the database relations.  We can check a database instance to see if an IC is violated, but we can never infer that an IC is true by looking at an instance.  Powerful and natural query languages exist.  Guidelines to translate ER to relational model (next class…)

Lecture 3Relational Data Model28 Look Ahead  Next topic: Relational Algebra  Read Textbook:  Chapter 7.4 – 7.6