Chapter 2 The Relational Data Model. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Relational model basics Integrity.

Slides:



Advertisements
Similar presentations
The Relational Model and Relational Algebra Nothing is so practical as a good theory Kurt Lewin, 1945.
Advertisements

The Relational Model Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
The Relational Database Model
Chapter 8 Normalization. © 2001 The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin Outline Modification anomalies Functional dependencies.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 9 Advanced Query Formulation with SQL.
The Relational Database Model
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 6 Developing Data Models for Business Databases.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 7 Normalization of Relational Tables.
The Relational Database Model. 2 Objectives How relational database model takes a logical view of data Understand how the relational model’s basic components.
7-1 Normalization - Outline  Modification anomalies  Functional dependencies  Major normal forms  Practical concerns.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
Chapter 9 Advanced Query Formulation with SQL. Outline Outer join problems Type I nested queries Type II nested queries and difference problems Nested.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Chapter 6 Developing Data Models for Business Databases.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 3 The Relational Data Model.
The Relational Database Model
3 The Relational Model MIS 304 Winter Class Objectives That the relational database model takes a logical view of data That the relational model’s.
The Relational Database Model
Database Systems Lecture # 8 11 th Feb,2011. The Relational Model of Data The term relation is basically just a mathematical term for a table. DBMS products.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
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.
Chapter 7 Normalization. Outline Modification anomalies Functional dependencies Major normal forms Relationship independence Practical concerns.
Chapter 7 Normalization. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Modification anomalies Functional dependencies.
Copyright © 2011 by Michael V. Mannino All rights reserved. Database Design, Application Development, and Administration, 5 th Edition Chapter 3 The Relational.
The Relational Database Model
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.
Chapter 10 Application Development with Views. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Background Creating.
Chapter 3 Query Formulation with SQL. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Background Getting started.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
Advanced Query Formulation with SQL. 9-2 Outline  Outer join problems  Type I nested queries  Type II nested queries and difference problems  Nested.
Chapter 9 Advanced Query Formulation with SQL. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Outer join problems.
9 Advanced Query Formulation with SQL (Chapter 9).
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
Database Systems, 9th Edition 1.  In this chapter, students will learn: That the relational database model offers a logical view of data About the relational.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
3 Copyright © 2006, Oracle. All rights reserved. Relational Data Model Part II.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 4 Query Formulation with SQL.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 3 The Relational Database Model.
Database Systems: Design, Implementation, and Management Ninth Edition Chapter 3 The Relational Database Model.
SQL – Simple Queries and JOIN MGMT 360 Database Management.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Copyright © 2011 by Michael V. Mannino All rights reserved. Database Design, Application Development, and Administration, 5 th Edition Quiz G4 Hyunwoo.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 10 Application Development with Views.
3 1 Database Systems The Relational Database Model.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
Week 2 Lecture The Relational Database Model Samuel ConnSamuel Conn, Faculty Suggestions for using the Lecture Slides.
Chapter 3 Query Formulation with SQL. Outline Background Getting started Joining tables Summarizing tables Reasoning tools Advanced problems Data manipulation.
Slide 1Chapter 9: Advanced Query Formulation with SQL Database Design, Application Development, and Administration, 5 th Edition Copyright © 2011 by Michael.
Chapter 2 The Relational Data Model. Outline Relational model basics Integrity rules Rules about referenced rows Relational Algebra.
The Relational Database Model
The Relational Data Model
Introduction to Database Management
Lecture 2 The Relational Model
Developing Data Models – Conversion Rules
Chapter 3 The Relational Database Model
The Relational Database Model
DCT 2053 DATABASE CONCEPT Chapter 2.2 CONTINUE
Database Design: Relational Model
Database Systems: Design, Implementation, and Management
Presentation transcript:

Chapter 2 The Relational Data Model

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Relational model basics Integrity rules Rules about referenced rows Relational Algebra

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Tables Relational database is a collection of tables Heading: table name and column names Body: rows, occurrences of data Student

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. 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))

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Common Data Types CHAR(L) VARCHAR(L) INTEGER FLOAT(P) Date/Time: DATE, TIME, TIMESTAMP DECIMAL(W, R) BOOLEAN

Relationships McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Alternative Terminology Table- oriented Set- oriented Record- oriented TableRelationRecord-type, file RowTupleRecord ColumnAttributeField

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Integrity Rules Entity integrity: primary keys –Each table has column(s) with unique values –Ensures entities are traceable Referential integrity: foreign keys –Values of a column in one table match values from a source table –Ensures valid references among tables

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Formal Definitions I Superkey: column(s) with unique values Candidate key: minimal superkey Null value: special value meaning value unknown or inapplicable Primary key: a designated candidate key; cannot contain null values Foreign key: column(s) whose values must match the values in a candidate key of another table

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Formal Definitions II Entity integrity –No two rows with the same primary key value –No null values in a primary key Referential integrity –Foreign keys must match candidate key of source table –Foreign keys in some cases can be null

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Course Table Example CREATE TABLE Course ( CourseNo CHAR(6), CrsDesc VARCHAR(250), CrsUnitsSMALLINT, CONSTRAINT PKCourse PRIMARY KEY(CourseNo), CONSTRAINT UniqueCrsDesc UNIQUE (CrsDesc) )

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Enrollment Table Example CREATE TABLE Enrollment ( OfferNo INTEGER, StdSSNCHAR(11), EnrGradeDECIMAL(3,2), CONSTRAINT PKEnrollment PRIMARY KEY (OfferNo, StdSSN), CONSTRAINT FKOfferNo FOREIGN KEY (OfferNo) REFERENCES Offering, CONSTRAINT FKStdSSN FOREIGN KEY (StdSSN) REFERENCES Student )

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Offering Table Example CREATE TABLE Offering ( OfferNo INTEGERNOT NULL, CourseNoCHAR(6)NOT NULL, OffLocationVARCHAR(50), OffDaysCHAR(6), OffTermCHAR(6)NOT NULL, OffYearINTEGERNOT NULL, FacSSNCHAR(11), OffTimeDATE, CONSTRAINT PKOffering PRIMARY KEY (OfferNo), CONSTRAINT FKCourseNo FOREIGN KEY (CourseNo) REFERENCES Course, CONSTRAINT FKFacSSN FOREIGN KEY (FacSSN) REFERENCES Faculty )

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Self-Referencing Relationships Foreign key that references the same table Represents relationships among members of the same set Not common but important when occurring

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Faculty Data

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Hierarchical Data Display

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Faculty Table Definition CREATE TABLE Faculty ( FacSSN CHAR(11) NOT NULL, FacFirstNameVARCHAR(50) NOT NULL, FacLastNameVARCHAR(50) NOT NULL, FacCityVARCHAR(50) NOT NULL, FacStateCHAR(2) NOT NULL, FacZipCodeCHAR(10)NOT NULL, FacHireDateDATE, FacDeptCHAR(6), FacSupervisor CHAR(11), CONSTRAINT PKFaculty PRIMARY KEY (FacSSN), CONSTRAINT FKFacSupervisor FOREIGN KEY (FacSupervisor) REFERENCES Faculty )

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Relationship Window with 1-M Relationships

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. M-N Relationships Rows of each table are related to multiple rows of the other table Not directly represented in the relational model Use two 1-M relationships and an associative table

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Referenced Rows Referenced row –Foreign keys reference rows in the associated primary key table –Enrollment rows refer to Student and Offering Actions on referenced rows –Delete a referenced row –Change the primary key of a referenced row –Referential integrity should not be violated

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Possible Actions Restrict: do not permit action on the referenced row Cascade: perform action on related rows Nullify: only valid if foreign keys accept null values Default: set foreign keys to a default value

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. SQL Syntax for Actions CREATE TABLE Enrollment ( OfferNoINTEGER NOT NULL, StdSSNCHAR(11) NOT NULL, EnrGradeDECIMAL(3,2), CONSTRAINT PKEnrollment PRIMARY KEY(OfferNo, StdSSN), CONSTRAINT FKOfferNo FOREIGN KEY (OfferNo) REFERENCES Offering ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT FKStdSSN FOREIGN KEY (StdSSN) REFERENCES Student ON DELETE RESTRICT ON UPDATE CASCADE )

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Relational Algebra Overview Collection of table operators Transform one or two tables into a new table Understand operators in isolation Classification –Table specific operators –Traditional set operators –Advanced operators

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Subset Operators

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Subset Operator Notes Restrict –Logical expression as input –Example: OffDays = 'MW' AND OffTerm = 'SPRING' AND OffYear = 2003 Project –List of columns is input –Duplicate rows eliminated if present Often used together

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Extended Cross Product Building block for join operator Builds a table consisting of all combinations of rows from each of the two input tables Produces excessive data Subset of cross product is useful (join)

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Extended Cross Product Example

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Join Operator Most databases have many tables Combine tables using the join operator Specify matching condition –Can be any comparison but usually = –PK = FK most common join condition –Relationship diagram useful when combining tables

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Join Example

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outer Join Overview Join excludes non matching rows Preserving non matching rows is important in some problems Outer join variations –Full outer join –One-sided outer join

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Right Outer Join Outer Join Operators Left Outer Join Join Matched rows using the join condition Unmatched rows of the left table Unmatched rows of the right table Full outer join

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Full Outer Join Example

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Traditional Set Operators A UNION B A INTERSECT B A MINUS B

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Union Compatibility Requirement for the traditional set operators Strong requirement –Same number of columns –Each corresponding column is compatible –Positional correspondence Apply to similar tables by removing columns first

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Summarize Operator Decision-making operator Compresses groups of rows into calculated values Simple statistical (aggregate) functions Not part of original relational algebra

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Summarize Example

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Divide Operator Match on a subset of values –Suppliers who supply all parts –Faculty who teach every IS course Specialized operator Typically applied to associative tables representing M-N relationships

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Division Example

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Relational Algebra Summary

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Summary Relational model is commercially dominant Learn primary keys, data types, and foreign keys Visualize relationships Understanding existing databases is crucial to query formulation