10/3/2000SIMS 257: Database Management -- Ray Larson Relational Algebra and Calculus University of California, Berkeley School of Information Management.

Slides:



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

Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
The Relational Database Model
Introduction to Structured Query Language (SQL)
SLIDE 1IS 202 – FALL 2005 Prof. Ray Larson UC Berkeley SIMS SIMS 202: Information Organization and Retrieval Normalization & The Relational.
9/30/1999SIMS 257: Database Management -- Ray Larson SQL Commands University of California, Berkeley School of Information Management and Systems SIMS.
Database Design University of California, Berkeley
SLIDE 1IS 257 – Fall 2010 Physical Database Design and Referential Integrity University of California, Berkeley School of Information IS 257:
Midterm Review Lecture 14b. 14 Lectures So Far 1.Introduction 2.The Relational Model 3.Disks and Files 4.Relational Algebra 5.File Org, Indexes 6.Relational.
SLIDE 1IS 257 – Spring 2004 Physical Database Design and Referential Integrity University of California, Berkeley School of Information Management.
Introduction to Structured Query Language (SQL)
SPRING 2004CENG 3521 The Relational Model Chapter 3.
SLIDE 1IS Fall 2004 Database Administration: Security and Integrity University of California, Berkeley School of Information Management.
SLIDE 1IS 257 – Fall 2008 Physical Database Design and Referential Integrity University of California, Berkeley School of Information IS 257:
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
SLIDE 1IS 257 – Fall 2006 Physical Database Design and Referential Integrity University of California, Berkeley School of Information IS 257:
8/28/97Information Organization and Retrieval Database Design: Normalization University of California, Berkeley School of Information Management and Systems.
9/28/2000SIMS 257: Database Management -- Ray Larson More on Physical Database Design and Referential Integrity University of California, Berkeley School.
The Relational Database Model. 2 Objectives How relational database model takes a logical view of data Understand how the relational model’s basic components.
10/4/2001SIMS 257: Database Management -- Ray Larson Relational Algebra and Calculus: Introduction to SQL University of California, Berkeley School of.
SLIDE 1IS Fall 2002 Physical Database Design and Referential Integrity University of California, Berkeley School of Information Management.
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
Chapter 14 & 15 Conceptual & Logical Database Design Methodology
Chapter 6 Physical Database Design. Introduction The purpose of physical database design is to translate the logical description of data into the technical.
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
Chapter 4 The Relational Model.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Chapter 9 Designing Databases Modern Systems Analysis and Design Sixth Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich.
TM 7-1 Copyright © 1999 Addison Wesley Longman, Inc. Physical Database Design.
MIS 301 Information Systems in Organizations Dave Salisbury ( )
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
Normalization (Codd, 1972) Practical Information For Real World Database Design.
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.
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 Relational Databases and SQL. Learning Objectives Understand techniques to model complex accounting phenomena in an E-R diagram Develop E-R diagrams.
Access Project 3 Notes. Introduction Maintaining the Database  Modifying the data to keep it up-to-date Restructure the Database  To change the database.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
FEN Introduction to the database field:  The Relational Model Seminar: Introduction to relational databases.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Copyright 2006 Prentice-Hall, Inc. Essentials of Systems Analysis and Design Third Edition Joseph S. Valacich Joey F. George Jeffrey A. Hoffer Chapter.
1 Chapter 6 Database Administration. 2 Introduction Database administration The process of managing a database Database administrator A person or an entire.
SLIDE 1IS 202 – FALL 2006 Prof. Ray Larson UC Berkeley SIMS SIMS 202: Information Organization and Retrieval Introduction to Database Design.
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)
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
Chapter 10 Designing Databases. Objectives:  Define key database design terms.  Explain the role of database design in the IS development process. 
Session 1 Module 1: Introduction to Data Integrity
Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall Chapter 9 Designing Databases 9.1.
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
Week 2 Lecture The Relational Database Model Samuel ConnSamuel Conn, Faculty Suggestions for using the Lecture Slides.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
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.
12/4/2001Information Organization and Retrieval Database Design University of California, Berkeley School of Information Management and Systems SIMS 202:
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
Lecture 2 The Relational Model
Translation of ER-diagram into Relational Schema
Chapter 3 The Relational Database Model
Physical Database Design and Referential Integrity
Physical Database Design
Database Design: Relational Model
Presentation transcript:

10/3/2000SIMS 257: Database Management -- Ray Larson Relational Algebra and Calculus University of California, Berkeley School of Information Management and Systems SIMS 257: Database Management

10/3/2000SIMS 257: Database Management -- Ray Larson Review Physical Database Design RAID Data Integrity

10/3/2000SIMS 257: Database Management -- Ray Larson Physical Design Decisions There are several critical decisions that will affect the integrity and performance of the system. –Storage Format –Physical record composition –Data arrangement –Indexes –Query optimization and performance tuning

10/3/2000SIMS 257: Database Management -- Ray Larson When to Index Tradeoff between time and space: –Indexes permit faster processing for searching –But they take up space for the index –They also slow processing for insertions, deletions, and updates, because both the table and the index must be modified Thus they SHOULD be used for databases where search is the main mode of interaction The might be skipped if high rates of updating and insertions are expected

10/3/2000SIMS 257: Database Management -- Ray Larson When to Use Indexes Rules of thumb –Indexes are most useful on larger tables –Specify a unique index for the primary key of each table –Indexes are most useful for attributes used as search criteria or for joining tables –Indexes are useful if sorting is often done on the attribute –Most useful when there are many different values for an attribute –Some DBMS limit the number of indexes and the size of the index key values –Some indexed will not retrieve NULL values

10/3/2000SIMS 257: Database Management -- Ray Larson RAID Technology Parallel Writes Disk 2Disk 3Disk 4Disk * * Parallel Reads Stripe One logical disk drive

10/3/2000SIMS 257: Database Management -- Ray Larson Raid 0 Parallel Writes Disk 2Disk 3Disk 4Disk * * Parallel Reads Stripe One logical disk drive

10/3/2000SIMS 257: Database Management -- Ray Larson RAID-1 Parallel Writes Disk 2Disk 3Disk 4Disk * * Parallel Reads Stripe

10/3/2000SIMS 257: Database Management -- Ray Larson RAID-2 Writes span all drives Disk 2Disk 3Disk 4Disk 1 1a 1b ecc ecc 2a 2b ecc ecc 3a 3b ecc ecc * * Reads span all drives Stripe

10/3/2000SIMS 257: Database Management -- Ray Larson RAID-3 Writes span all drives Disk 2Disk 3Disk 4Disk 1 1a 1b 1c ecc 2a 2b 2c ecc 3a 3b 3c ecc * * Reads span all drives Stripe

10/3/2000SIMS 257: Database Management -- Ray Larson Raid-4 Disk 2Disk 3Disk 4Disk ecc ecc ecc * * Stripe Parallel Writes Parallel Reads

10/3/2000SIMS 257: Database Management -- Ray Larson RAID-5 Parallel Writes Disk 2Disk 3Disk 4Disk ecc ecc * * Parallel Reads Stripe

10/3/2000SIMS 257: Database Management -- Ray Larson Integrity Constraints The constraints we wish to impose in order to protect the database from becoming inconsistent. Five types –Required data –attribute domain constraints –entity integrity –referential integrity –enterprise constraints

10/3/2000SIMS 257: Database Management -- Ray Larson

10/3/2000SIMS 257: Database Management -- Ray Larson Required Data Some attributes must always contain a value -- they cannot have a null For example: – Every employee must have a job title. –Every diveshop diveitem must have an order number and an item number.

10/3/2000SIMS 257: Database Management -- Ray Larson Attribute Domain Constraints Every attribute has a domain, that is a set of values that are legal for it to use. For example: –The domain of sex in the employee relation is “M” or “F” Domain ranges can be used to validate input to the database.

10/3/2000SIMS 257: Database Management -- Ray Larson Entity Integrity The primary key of any entity cannot be NULL.

10/3/2000SIMS 257: Database Management -- Ray Larson Referential Integrity A “foreign key” links each occurrence in a relation representing a child entity to the occurrence of the parent entity containing the matching candidate key. Referential Integrity means that if the foreign key contains a value, that value must refer to an existing occurrence in the parent entity. For example: –Since the Order ID in the diveitem relation refers to a particular diveords item, that item must exist for referential integrity to be satisfied.

10/3/2000SIMS 257: Database Management -- Ray Larson Referential Integrity Referential integrity options are declared when tables are defined (in most systems) There are many issues having to do with how particular referential integrity constraints are to be implemented to deal with insertions and deletions of data from the parent and child tables.

10/3/2000SIMS 257: Database Management -- Ray Larson Insertion rules A row should not be inserted in the referencing (child) table unless there already exists a matching entry in the referenced table. Inserting into the parent table should not cause referential integrity problems. Sometimes a special NULL value may be used to create child entries without a parent or with a “dummy” parent.

10/3/2000SIMS 257: Database Management -- Ray Larson Deletion rules A row should not be deleted from the referenced table (parent) if there are matching rows in the referencing table (child). Three ways to handle this –Restrict -- disallow the delete –Nullify -- reset the foreign keys in the child to some NULL or dummy value –Cascade -- Delete all rows in the child where there is a foreign key matching the key in the parent row being deleted

10/3/2000SIMS 257: Database Management -- Ray Larson Referential Integrity This can be implemented using external programs that access the database newer databases implement executable rules or built-in integrity constraints (e.g. Access)

10/3/2000SIMS 257: Database Management -- Ray Larson Enterprise Constraints These are business rule that may affect the database and the data in it –for example, if a manager is only permitted to manage 10 employees then it would violate an enterprise constraint to manage more

10/3/2000SIMS 257: Database Management -- Ray Larson Today Relational Operations Relational Algebra Relational Calculus Introduction to SQL via Access

10/3/2000SIMS 257: Database Management -- Ray Larson Relational Algebra Operations Select Project Product Union Intersect Difference Join Divide

10/3/2000SIMS 257: Database Management -- Ray Larson Select Extracts specified tuples (rows) from a specified relation (table).

10/3/2000SIMS 257: Database Management -- Ray Larson Project Extracts specified attributes(columns) from a specified relation.

10/3/2000SIMS 257: Database Management -- Ray Larson Product Builds a relation from two specified relations consisting of all possible concatenated pairs of tuples, one from each of the two relations. abcabc xyxy xyxyxyxyxyxy aabbccaabbcc Product

10/3/2000SIMS 257: Database Management -- Ray Larson Union Builds a relation consisting of all tuples appearing in either or both of two specified relations.

10/3/2000SIMS 257: Database Management -- Ray Larson Intersect Builds a relation consisting of all tuples appearing in both of two specified relations

10/3/2000SIMS 257: Database Management -- Ray Larson Difference Builds a relation consisting of all tuples appearing in first relation but not the second.

10/3/2000SIMS 257: Database Management -- Ray Larson Join Builds a relation from two specified relations consisting of all possible concatenated pairs of, one from each of the two relations, such that in each pair the two tuples satisfy some condition. A1 B1 A2 B1 A3 B2 B1 C1 B2 C2 B3 C3 A1 B1 C1 A2 B1 C1 A3 B2 C2 (Natural or Inner) Join

10/3/2000SIMS 257: Database Management -- Ray Larson Outer Join Outer Joins are similar to PRODUCT -- but will leave NULLs for any row in the first table with no corresponding rows in the second. A1 B1 A2 B1 A3 B2 A4 B7 B1 C1 B2 C2 B3 C3 A1 B1 C1 A2 B1 C1 A3 B2 C2 A4 * * Outer Join

10/3/2000SIMS 257: Database Management -- Ray Larson Divide Takes two relations, one binary and one unary, and builds a relation consisting of all values of one attribute of the binary relation that match (in the other attribute) all values in the unary relation. a xyxy xyzxyxyzxy aaabcaaabc Divide

10/3/2000SIMS 257: Database Management -- Ray Larson ER Diagram: Acme Widget Co. Contains Part Part#Count Price Customer Quantity Orders Cust# Invoice Writes Sales-Rep Invoice# Sales Rep# Line-Item Contains Part# Invoice# Cust# Hourly Employee ISA Emp# Wage

10/3/2000SIMS 257: Database Management -- Ray Larson Employee

10/3/2000SIMS 257: Database Management -- Ray Larson Part

10/3/2000SIMS 257: Database Management -- Ray Larson Sales-Rep Hourly

10/3/2000SIMS 257: Database Management -- Ray Larson Customer

10/3/2000SIMS 257: Database Management -- Ray Larson Invoice

10/3/2000SIMS 257: Database Management -- Ray Larson Line-Item

10/3/2000SIMS 257: Database Management -- Ray Larson Join Items

10/3/2000SIMS 257: Database Management -- Ray Larson Relational Algebra What is the name of the customer who ordered Large Red Widgets? –Select “large Red Widgets” from Part as temp1 –Join temp1 with Line-item on Part # as temp2 –Join temp2 with Invoice on Invoice # as temp3 –Join temp3 with customer on cust # as temp4 –Project Name from temp4

10/3/2000SIMS 257: Database Management -- Ray Larson Relational Calculus Relational Algebra provides a set of explicit operations (select, project, join, etc) that can be used to build some desired relation from the database. Relational Calculus provides a notation for formulating the definition of that desired relation in terms of the relations in the database without explicitly stating the operations to be performed SQL is based on the relational calculus.

10/3/2000SIMS 257: Database Management -- Ray Larson SQL Structured Query Language Database Definition and Querying Basic language is standardized across relational DBMSs. Each system may have proprietary extensions to standard. Relational Calculus combines Select, Project and Join operations in a single command. SELECT.

10/3/2000SIMS 257: Database Management -- Ray Larson SELECT Syntax: –SELECT attr1, attr2,…, attr3 FROM rel1 r1, rel2 r2,… rel3 r3 WHERE condition1 {AND | OR} condition2 ORDER BY attr1, attr3 Examples in Access...