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

Slides:



Advertisements
Similar presentations
Relational Model dww-database system.
Advertisements

IS698: Database Management Min Song IS NJIT. The Relational Data Model.
Relational Database Design UNIT II 1. 2 Advantages of Using Database Systems Centralized control of a firm’s data Redundancy can be reduced (avoid keeping.
Chapter 3 : Relational Model
Relational Model (CB Chapter 4) CPSC 356 Database Ellen Walker Hiram College.
The Relational Model Class 2 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) (From ER to Relational)
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: >
Relational Database Management System A type of database in which records are stored in relational form is called relational database management system.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 3 The Relational Data Model.
Database Architecture The Relational Database Model.
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.
Module Title? DBMS E-R Model to Relational Model.
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
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints.
CG084&085 / / 1 The Relational Data Model Properties of Relations Keys and Constraints.
Instructor: Churee Techawut Basic Concepts of Relational Database Chapter 5 CS (204)321 Database System I.
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.
R ELATIONAL D ATA M ODEL Joe Meehean 1. R ELATIONAL D ATA M ODEL Data stored as a set of relations really just tables Tables related to one another through.
Copyright © 2011 by Michael V. Mannino All rights reserved. Database Design, Application Development, and Administration, 5 th Edition Chapter 3 The Relational.
Chapter 2 The Relational Data Model. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Relational model basics Integrity.
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.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
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.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Announcements Reading for Monday –4.6 Homework 3 – Due 9/29.
Chapter 2 Introduction to Relational Model. Example of a Relation attributes (or columns) tuples (or rows) Introduction to Relational Model 2.
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
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. 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.
Ch 7: Normalization-Part 1
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
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.
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.
Chapter 2 The Relational Data Model. Outline Relational model basics Integrity rules Rules about referenced rows Relational Algebra.
Chapter 2: Relational Model
Chapter 2: Intro to Relational Model
Database Design The Relational Model Text Ch5
Chapter 3: Intro to Relational Model
ER Modeling Exercise Consider a set of courses, both at grad and undergrad level. Each course has at least one section. Each section is taught by only.
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
The Relational Model Transparencies
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 2: Intro to Relational Model
Chapter 4 The Relational Model Pearson Education © 2009.
INSTRUCTOR: MRS T.G. ZHOU
Presentation transcript:

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

Important Points Relational Model Definitions Relational Keys Relational Integrity

Tables Relational database is a collection of tables Heading: table name and column names Body: rows, occurrences of data Student

CREATE TABLE Statement CREATE TABLE Student ( StdSSN CHAR(11), StdFirstNameVARCHAR(50), StdLastNameVARCHAR(50), StdCityVARCHAR(50), StdStateCHAR(2), StdZipCHAR(10), StdMajor CHAR(6), StdClass CHAR(6), StdGPADECIMAL(3,2))

Common Data Types CHAR(L) VARCHAR(L) INTEGER FLOAT(P) Date/Time: DATE, TIME, TIMESTAMP DECIMAL(W, R) BOOLEAN

Relationships

Alternative Terminology Table-orientedSet-orientedRecord-oriented TableRelationRecord-type, file RowTupleRecord ColumnAttributeField

Relational Model Definitions A relation is a table with columns and rows. An attribute is a named column of a relation. A tuple is a row of a relation. A domain is a set of allowable values for one or more attributes. The degree of a relation is the number of attributes it contains. The cardinality of a relation is the number of tuples it contains. A relational database is a collection of normalized relations with distinct relation names. The intension of a relation is the structure of the relation including its domains. The extension of a relation is the set of tuples currently in the relation.

Example

Try It 1) What is the name of the relation? 2) What is the cardinality of the relation? 3) What is the degree of the relation? 4) What is the domain of StdGPA? What is the domain of StdSSN? Student

Database A database consists of multiple relations Information about an enterprise is broken up into parts, with each relation storing one part of the information account : stores information about accounts depositor : stores information about which customer owns which account customer : stores information about customers Storing all information as a single relation such as bank(account_number, balance, customer_name,..) results in  repetition of information (e.g., two customers own an account)  the need for null values (e.g., represent a customer without an account)

Formal Definition The relational model may be visualized as tables and fields, but it is formally defined in terms of sets and set operations. A relation schema R with attributes A = is denoted R(A1, A2, …, An) where each Ai is an attribute name that ranges over a domain Di denoted dom(Ai). Example: Product(id, name, supplierId, categoryId, price)  R = Product (relation name)  Set A = {id, name, supplierId, categoryId, price}  dom(price) is set of all possible positive currency values  dom(name) is set of all possible strings that represent people's names

Relation Schemas and Instances A relation schema is a definition of a single relation.  The relation schema is the intension of the relation. A relational database schema is a set of relation schemas. A relation instance denoted r(R) over a relation schema R(A1, A2, …, An) is a set of n-tuples where each di is an element of dom(Ai) or is null.  The relation instance is the extension of the relation.  A value of null represents a missing or unknown value.

Cartesian Product (review) The Cartesian product written as D1 x D2 is a set operation that takes two sets D1 and D2 and returns the set of all ordered pairs such that the first element is a member of D1 and the second element is a member of D2. Example:  D1 = {1,2,3}  D2 = {A,B}  D1 x D2 = {(1,A), (2,A), (3,A), (1,B), (2,B), (3,B)} Practice Questions:  1) Compute D2 x D1.  2) Compute D2 x D2.  3) If |D| denotes the number of elements in set D, how many elements are there in D1 x D2 in general. What is the cardinality of D1 x D2 x D1 x D1?

Relation Instance A relation instance r(R) can also be defined as a subset of the Cartesian product of the domains of all attributes in the relation schema. That is, r(R) dom(A1) x dom(A2) x … x dom(An) Example:  R = Person(id, firstName, lastName)  dom(id) = {1,2}, dom(firstName) = {Joe, Steve}  dom(lastName) = {Jones, Perry}  dom(id) x dom(firstName) x dom(lastName) = { (1,Joe,Jones), (1,Joe,Perry), (1,Steve,Jones), (1,Steve,Perry), (2,Joe,Jones), (2,Joe,Perry), (2,Steve,Jones), (2,Steve,Perry)}

Properties of Relations A relation has several properties: Each relation name is unique.  No two relations have the same name. Each cell of the relation (value of a domain) contains exactly one atomic (single) value. Each attribute of a relation has a distinct name. The values of an attribute are all from the same domain. Each tuple is distinct. There are no duplicate tuples.  This is because relations are sets. In SQL, relations are bags. The order of attributes is not important. The order of tuples has no significance.

Relational Keys Keys are used to uniquely identify a tuple in a relation.  Note that keys apply to the relational schema not to the relational instance. That is, looking at the current instance cannot tell you for sure if the set of attributes is a key. A superkey is a set of attributes that uniquely identifies a tuple in a relation. A key is a minimal set of attributes that uniquely identifies a tuple in a relation. A candidate key is one of the possible keys of a relation. A primary key is the candidate key designated as the distinguishing key of a relation. A foreign key is a set of attributes in one relation referring to a candidate key of another relation.  Many DDLs require that a foreign reference a primary key.

Example Relations Employee-Project Database:  Employees have a unique number, name, title, and salary.  Projects have a unique number, name, and budget.  An employee may work on multiple projects and a project may have multiple employees. An employee on a project has a particular responsibility and duration on the project. Relations: EMP(ENO, ENAME, TITLE, SAL) PROJ (PNO, PNAME, BUDGET) WORKSON(ENO, PNO, RESP, DUR) Underlined attributes denote keys.

Example Relation Instances Questions: 1) Is ename a key for emp? 2) Is eno a key for WorksOn? 3) List all the superkeys for WorksOn.

Practice Questions Questions: 1) List the candidate keys for the relation. 2) Pick a primary key for the relation. 3) Is name a candidate key for Person? 4) List all the superkeys for Person. Assumptions: 1) A person has only one driver’s license. 2) A driver’s license uniquely identifies a person.

Relational Integrity Integrity rules are used to insure the data is accurate. Constraints are rules or restrictions that apply to the database and limit the data values it may store. Types of constraints:  Domain constraint - Every value for an attribute must be an element of the attribute's domain or be null. null represents a value that is currently unknown or not applicable. null is not the same as zero or an empty string.  Entity integrity constraint - In a base relation, no attribute of a primary key can be null and each value must be unique.  Referential integrity constraint - If a foreign key exists in a relation, then the foreign key value must match a primary key value of a tuple in the referenced relation or be null.

Foreign Keys Example

Integrity Questions Question: 1) Find all violations of integrity constraints in these three relations.

General Constraints There are more general constraints that some DBMSs can enforce. These constraints are often called enterprise constraints or semantic integrity constraints. Examples:  An employee cannot work on more than 2 projects.  An employee cannot make more money than their manager.  An employee must be assigned to at least one project. Ensuring the database follows these constraints is usually achieved using triggers and assertions.