Relational Model (CB Chapter 4) CPSC 356 Database Ellen Walker Hiram College.

Slides:



Advertisements
Similar presentations
The Relational Model Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
Advertisements

Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
CSC271 Database Systems Lecture # 5. Summary: Previous Lecture  Database languages  Functions of a DBMS  DBMS environment  Data models and their categories.
The Relational Model System Development Life Cycle Normalisation
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
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 Minggu 2, Pertemuan 3 The Relational Model Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
1 Pertemuan 04 MODEL RELASIONAL Matakuliah: >/ > Tahun: > Versi: >
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
Thomas Connolly and Carolyn Begg’s
Relational Database Management System A type of database in which records are stored in relational form is called relational database management system.
Database Architecture The Relational Database Model.
Chapter 3 Relational Model Chapter 4 in Textbook.
Databases Illuminated
CSC271 Database Systems Lecture # 6. Summary: Previous Lecture  Relational model terminology  Mathematical relations  Database relations  Properties.
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Chapter 4 The Relational Model Pearson Education © 2014.
© Pearson Education Limited, Chapter 2 The Relational Model Transparencies.
The Relational Model These slides are based on the slides of your text book.
Relational Model Session 6 Course Name: Database System Year : 2012.
Chapter 4 The Relational Model.
Chapter 3 The Relational Model Transparencies Last Updated: Pebruari 2011 By M. Arief
The Relational Model. Review Why use a DBMS? OS provides RAM and disk.
SQL Data Definition (CB Chapter 6) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley.
CG084&085 / / 1 The Relational Data Model Properties of Relations Keys and Constraints.
Module 3: The Relational Model.  Overview Terminology Relational Data Structure Mathematical Relations Database Relations Relational Keys Relational.
Chapter 3 The Relational Model. 2 Chapter 3 - Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
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.
Relational Data Model Ch. 7.1 – 7.3 John Ortiz Lecture 3Relational Data Model2 Why Study Relational Model?  Most widely used model.  Vendors: IBM,
The Relational Model Pertemuan 03 Matakuliah: M0564 /Pengantar Sistem Basis Data Tahun : 2008.
Relational Database. Database Management System (DBMS)
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Concepts 2440: 180 Database Concepts Instructor:
Announcements Reading for Monday –4.6 Homework 3 – Due 9/29.
12/2/2015CPSC , CPSC , Lecture 41 Relational Model.
L8-2-S1 Misc Topics © M.E. Fayad SJSU -- CmpE Database Design Dr. M.E. Fayad, Professor Computer Engineering Department, Room #283I College of.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
The Relational Model. 2 Relational Model Terminology u A relation is a table with columns and rows. –Only applies to logical structure of the database,
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
Mapping ER to Relational Model Each strong entity set becomes a table. Each weak entity set also becomes a table by adding primary key of owner entity.
CSCI 6315 Applied Database Systems Review for Midterm Exam I Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
Chapter 4 The Relational Model Pearson Education © 2009.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
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 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
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 Relational Database Model
Data Base System Lecture 6: Relational Model
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
DATABASE SYSTEM.
Chapter 4 The Relational Model Pearson Education © 2009.
The Relational Model Textbook /7/2018.
The Relational Model Transparencies
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Presentation transcript:

Relational Model (CB Chapter 4) CPSC 356 Database Ellen Walker Hiram College

Relational Model Proposed by E.F. Codd, 1970 Goals –Data independence (physical vs. conceptual) –Normalization (avoiding redundancy) –Set-oriented data manipulation language (relational algebra) Examples of Relational DBMS: –DBMS System R (IBM), Ingres (UC Berkeley) –Oracle (all versions), Access, RDB, DB2 …

Terminology A relation (instance) is a table with columns and rows. –(don’t confuse with relationships in ER models) An attribute is a named column of a table. –(corresponds to simple attribute in ER) A domain is the set of allowable values for an attribute A tuple is a row of a table.

More Terminology The degree or arity of a relation is its number of attributes (columns) The cardinality of a relation is its number of tuples (rows) A relational database is a collection of normalized relations with distinct names. –We’ll get to normalization later!

Example Relation (Phone Book) Attributes: First, last, dept, , etc. Domain for Title: {Prof, Inst, Assoc, Asst} Tuple: (Obie,Slotterbeck,CS,Obie,5275,Prof) Degree = 6, Cardinality = 4 FirstLastDept PhoneTitle ObieSlotterbeckCSObie5275Prof IrinaLomonosovCSLomonosovI5002Inst EllenWalkerCSWalkerEL5250Prof AngelaGuercioCSGuercioA6048Asst

Order Doesn’t Matter! This is the same phone book relation. TitleFirstPhoneLastDept LomonosovIInstIrina5002LomonosovCS ObieProfObie5275SlotterbeckCS WalkerELProfEllen5250WalkerCS GuercioAAsstAngela5048GuercioCS

Sets and Subsets A set is an unordered collection of unique elements Set S = {1,2,3} “1 is an element of S” {a,b,c} = {a,c,b} A subset of a set is another set whose elements all come from the original set. {a,b} is a subset of {a,c,b} {1,2,3} is a subset of {1,2,3} {1,2,4} is not a subset of {1,2,3} {} (the empty set) is a subset of every set!

Mathematical Relations Cartesian product: a set of ordered pairs, where each contains one element from each original set {1,2,3} x {a, b} = {(1,a), (1,b), (2,a), (2,b), (3,a), (3,b)} Relation: any subset of a Cartesian product –R1 = {(1,a),(2,b),(3,a)} –R2 = {(1,a), (1,b), (2,b), (3,b)} –R3 = { }

Bigger Relations First, take the cross product of n sets –If n = 3, get triples; if n=4, get quadruples –For arbitrary n, get “n-tuples” Now, take a subset of that big cross product –Several n-tuples Arrange them in rows, so the commas line up –Looks familiar… Domains of attributes are sets from the cross product.

Database Schemas A schema describes a database, but not the data Relation schema: set of attribute and domain name pairs (First: char-string)(Last: char-string) (Dept: {CS,Math,Comm,Econ,Mgmt, etc.}) (Phone: 4-digit-string)( char-string) (Title: {Inst,Asst,Assoc,Prof}) Relational Database Schema: set of relational schemas, each with a distinct name and integrity constraints (later)

Properties of (Database) Relations Every relation has a unique name Every attribute has a unique name Attribute’s values are all from its domain Because relations are sets… –No duplicate tuples –Order of tuples doesn’t matter (theoretically) Every cell contains a single value (single- valued attributes)

Single-valued Attributes “Oldest-child” is an ok attribute “Children” is not, because it is likely to be multi-valued Break up composite attributes into multiple attributes –Name --> First-name, Middle-init, Last-name Use “relationships” in the ER sense for multivalued attributes.

Keys Superkey: set of attributes that uniquely identifies a tuple. – (The whole tuple is always a superkey - why?) Candidate Key: a superkey that doesn’t have a proper subset that is also a superkey Primary Key: the candidate key that is selected by the designer (often generated) Foreign Key: Set of attributes in one relation that matches the Primary key of another.

Properties of a Candidate Key Uniqueness –The set of attribute values in the candidate key uniquely identifies a tuple Irreducibility –If one attribute is removed from the candidate key, then uniqueness no longer holds

NULL NULL is considered a member of every domain NULL means: –Value is currently unknown –Value is not applicable for this entry (e.g. “spouse” of a single person) Don’t confuse NULL with –Zero –Blank or empty string

Relational Schema “Shorthand” List the relation name first Attribute names in parentheses following the relation name Primary key attribute(s) underlined Example –Branch (BranchNo, street, city, postcode) –Staff (StaffNo, fName, position, sex, DOB, salary, BranchNo) Arrow from foreign key to its referent

Integrity Constraints Rules that apply to all instances of any database If these rules are violated, the instance is not a legal database (it doesn’t “make sense”) Some come from business rules of enterprise –“Students can take only 1 course in 3-week term” Others from the schema design –“InstructorID cannot be NULL and must match the ID of a listed faculty member”

Key Constraint Specifies which attributes compose a candidate key (or primary key) for the relation Example: –{first, last} and { } are both keys of the Phone Book relation Generally, only the primary key is specified In practice, an auto-generated id number is used as the key

Basic Integrity Constraints –Entity Integrity: No attribute of a primary key can be NULL for any tuple. This constraint is implicit in the KEY constraint in SQL –Referential Integrity: If a relation has a foreign key, either the foreign key is NULL, or the foreign key matches the primary key of an existing tuple in another relation. Attribute names do not have to be the same

Maintaining Referential Integrity Adding a new tuple –Add with NULL foreign keys –Add tuple in the other relation (with primary key matching the foreign key) first Deleting a tuple –Find all tuples in other relations whose foreign keys match this one –Either delete those tuples, or change their foreign keys to NULL Modifying a tuple –If a foreign key is changed, make sure that the new value points to an existing tuple or is NULL

Summary of Constraints Domain constraint –Each attribute’s values come from its domain Key constraint –Every relation has a primary key Entity integrity constraint –No NULL primary key attributes Referential integrity constraint –Foreign keys are NULL or refer to existing tuples’ primary keys Semantic constraints –Any additional constraints that must be satisfied based on the client’s needs

Views “Relations” that appear to exist, but actually combine attributes from multiple base (implemented) relations. When a base table changes, the view changes & vice versa Useful for –Security: limit which attributes a user sees –Customization –Simplification