Lecture 8 Database Theory & Practice (2) : The Relational Data Model UFCEKG-20-2 Data, Schemas & Applications.

Slides:



Advertisements
Similar presentations
Displaying Data from Multiple Tables. Objectives After completing this lesson, you should Be able to do the following: Write SELECT statements to accessWrite.
Advertisements

Copyright  Oracle Corporation, All rights reserved. 3 Displaying Data from Multiple Tables.
Displaying Data from Multiple Tables. Objectives After completing this lesson, you should be able to do the following:  Write SELECT statements to access.
Displaying Data from Multiple Tables. Objectives After completing this lesson, you should be able to do the following: Write SELECT statements to access.
Chapter 4 JOINING TABLES & FUNCTION Lecture by Ty Rasmey
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Bogdan Shishedjiev SQL1 SQL Reminder of SQL. Bogdan Shishedjiev SQL 2 Subsets of language Data definition language (DDL) –Domain definition –Schema definition.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Extended SQL & The Relational Calculus.
SQL zSeQueL zSQL zSQL ybetter support for Algebraic operations zSQL Post-Relational yrow and column types, stored procedures, triggers,
CS263 Lecture 19 Query Optimisation.  Motivation for Query Optimisation  Phases of Query Processing  Query Trees  RA Transformation Rules  Heuristic.
Chapter 3 An Introduction to Relational Databases.
Logical Layer The Relational Data Model + SQL. Abstraction Layers zConceptual yWhat data is held xAn Image and its meta-data xEntity-Relationship model.
The Relational Data Model zE.F Codd A Relational Data Model for Large Shared Data Banks (1970) zThe basic model used by Access, Oracle, DB2 zAll Relational.
Session 3: SQL (B): Parts 3 & 4 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram.
Database Systems: A Practical Approach to Design, Implementation and Management International Computer Science S. Carolyn Begg, Thomas Connolly Lecture.
OO - Lecture 4 Tutorial Review Associations Inheritance of Functions Polymorphism.
Logical Operators Operator AND OR NOT Meaning Returns TRUE if both component conditions are TRUE Returns TRUE if either component condition is TRUE Returns.
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
CS370 Spring 2007 CS 370 Database Systems Lecture 7 The Relational model.
Chapter 3 Section 3.4 Relational Database Operators
o At the end of this lesson, you will be able to:  Describe the life-cycle development phases  Discuss the theoretical and physical aspects of a relational.
Copyright  Oracle Corporation, All rights reserved. I Introduction.
4-1 Copyright  Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
RELATIONAL ALGEBRA Relational Database Handout - 3.
Dr. Philip Cannata 1 Programming Languages Prolog Part 3 SQL & Prolog.
Displaying Data from Multiple Tables (Join). EMPNO DEPTNO LOC NEW YORK CHICAGO NEW YORK DALLAS.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Introduction to Relational Databases &
MSc IT UFIE8K-15-M Data Management Prakash Chatterjee Room 3P16
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Cursors These slides are licensed under.
1 Information Retrieval and Use (IRU) CE An Introduction To SQL Part 1.
An Introduction To SQL - Part 1 (Special thanks to Geoff Leese)
Copyright س Oracle Corporation, All rights reserved. I Introduction.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
SQL- DQL (Oracle Version). 2 SELECT Statement Syntax SELECT [DISTINCT] column_list FROM table_list [WHERE conditional expression] [GROUP BY column_list]
Session 2: SQL (A): Parts 1 and 2 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram.
SQL SeQueL -Structured Query Language SQL SQL better support for Algebraic operations SQL Post-Relational row and column types,
4 Displaying Data from Multiple Tables Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina,
Copyright س Oracle Corporation, All rights reserved. 4 Displaying Data from Multiple Tables.
I-1 Copyright س Oracle Corporation, All rights reserved. Data Retrieval.
SQL: Part 2 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram. Not for commercial.
Relational Algebra Operators
An Introduction To SQL Part 2 (Special thanks to Geoff Leese)
Presented By: Miss N. Nembhard. Relation Algebra Relational Algebra is : the formal description of how a relational database operates the mathematics.
Copyright س Oracle Corporation, All rights reserved. I Introduction.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Collection Operators These slides are.
2-1 Limiting Rows Using a Selection “…retrieve all employees in department 10” EMP EMPNO ENAME JOB... DEPTNO 7839KINGPRESIDENT BLAKEMANAGER CLARKMANAGER.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Collection Operators These slides are.
Copyright س Oracle Corporation, All rights reserved. 12 Creating Views.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Displaying Data from Multiple Tables (Join) Displaying Data from Multiple Tables (Join) Displaying Data from Multiple Tables (Join Displaying Data from.
Copyright  Oracle Corporation, All rights reserved. 4 Displaying Data from Multiple Tables.
Displaying Data from Multiple Tables. Objectives After completing this lesson, you should be able to do the following: –Write SELECT statements to access.
4 Displaying Data from Multiple Tables. 4-2 Objectives At the end of this lesson, you should be able to: Write SELECT statements to access data from more.
Communicating with a RDBMS Using SQL Database SQL> SELECT loc 2 FROM dept; SQL> SELECT loc 2 FROM dept; SQL statement is entered Statement is sent to database.
Ritu CHaturvedi Some figures are adapted from T. COnnolly
Relational Normalization Theory
COMP3017 Advanced Databases
Displaying Data from Multiple Tables
Displaying Data from Multiple Tables
What Is a View? EMPNO ENAME JOB EMP Table EMPVU10 View
Data Base System Lecture 6: Relational Model
(SQL) Displaying Data from Multiple Tables
Lecture 16 : The Relational Data Model
Restricting and Sorting Data
Lecture 16 : The Relational Data Model
Displaying Data from Multiple Tables
Presentation transcript:

Lecture 8 Database Theory & Practice (2) : The Relational Data Model UFCEKG-20-2 Data, Schemas & Applications

Origins of the Relational Model o The relational model was developed by EF Codd in the early 1970s. o Commercial systems based on the relational model appeared in the late 1970s. o At present there are several hundred relational DBMSs and most computer vendors support 'relational' software. o Examples of well-known products include Oracle, DB2, Sybase, MySQL, MS.SQL Server and MS Access. Informally, a relational system is a system in which: 1. The data is perceived by the user as tables (and nothing but tables). 2. The operators available to the user for (e.g.) retrieval are operators that derive “new” tables from "old" ones. For example, there is one operator, restrict, which extract a subset of the rows of a given table, and another, project, which extracts a subset of columns - and a row subset and a column subset of a table can both be regarded in turn as tables in their own right.

Components and terminology (1) The model uses terminology taken from mathematics, particularly set theory and predicate logic. Basic terminology used in relational theory includes: o relation - this corresponds to a table or flat file with columns and rows o tuple - a row of a relation o attribute - a named column of a relation o domain - the set of allowable values for one or more attributes o degree of a relation - the number of attributes it contains o cardinality of relation - the number of tuples it contains.

Components and terminology (2)

Properties of relations o There is only one data structure in the relational data model - the relation. o Every relation and every attribute within a relation must have a distinct name. o Attribute (column) values of a relation are atomic (i.e. single valued). o All values in an attribute (column) are taken from same domain. o The ordering of columns in a relation is not significant. o Duplicate tuples (rows) are not allowed (e.g. each row in a relation must be distinct). o The ordering of tuples (rows) and attributes (columns) is not significant.

Relational algebra & relational calculus o Relational algebra (ra) and relational calculus (rc) are both formal (mathematically based) languages defined by EF Codd. o ra & rc are logically equivalent languages. ra is “procedural” and rc is “declarative” in nature. o ra and rc are the formal grounding of the relational database model and illustrate the basic operations required by any data manipulation language such as SQL. o Relational algebra is an offshoot of first-order logic, is a set of relations closed under operators. Operators operate on one or more relations to yield a relation.first-order logicrelationsclosedoperators o The “closure” property relates to the fact that from any given relational operation another relation is output - this is often referred to as the “relations in – relations out” property.

Relational algebra operators (1) o Each relational operator takes one or more relations as its input and produces a new relation as output (closure). Codd originally defined eight operators, in two classes: Set operators:UNIONINTERSECTION DIFFERENCEDIVIDE The special relational operators: RESTRICTPROJECT JOINCartesian PRODUCT

Relational algebra operators (2)

Relational algebra operators (3) dept – emp – salgrade example (1) Department : dept (depno, dname, location) Employee : emp (empno, ename, mgr, sal, deptno) Salary Grade : salgrade (grade, losal, hisal)

Relational algebra operators (4) dept – emp – salgrade example (2) o dept table deptnodnamelocation 10AccountingNew York 20ResearchDallas 30SalesChicago 40OperationsBoston

Relational algebra operators (5) dept – emp – salgrade example (3) empnoenamemgrsaldeptno 7369SMITH7902 £ ALLEN7698£1, WARD7698£1, JONES7839£2, MARTIN7698£1, BLAKE7839£2, CLARK7839£2, SCOTT7566£3, KING£5, TURNER7698£1, ADAMS7788£1, JAMES7698 £ FORD7566£3, MILLER7782£1, o emp table

Relational algebra operators (6) dept – emp – salgrade example (4) gradelosalhisal 1£700.00£1, £1,201.00£1, £1,401.00£2, £2,001.00£3, £3,001.00£99, o salgrade table

Relational algebra operators (7) dept – emp – salgrade example (5) o Restrict => s ubset of the Rows in a Table RESTRICT EMP WHERE sal > 2000 empnoenamemgrsaldeptno 7566JONES7839£2, BLAKE7839£2, CLARK7839£2, SCOTT7566£3, KING£5, FORD7566£3,

Relational algebra operators (8) dept – emp – salgrade example (6) o Project => subset the Columns in a Table PROJECT EMP [EMPNO, SAL,DEPTNO] empnosal deptno 7369£ £1, £1, £2, £1, £2, £2, £3, £5, £1, £1, £ £3, £1,

Relational algebra operators (9) dept – emp – salgrade example (7) o Restrict-Project RESTRICT EMP WHERE SAL >2000 PROJECT EMP[EMPNO, SAL, DEPTNO] empnosaldeptno 7566£2, £2, £2, £3, £5, £3, call this EMPX Could you reverse these operations - always? ( project then restrict?)

Relational algebra operators (10) dept – emp – salgrade example (8) o Product => combine each row of one table with each row of the other PRODUCT DEPT with EMPX empnosalEMPX. deptno dept. Depno dnameloc 7566£2, AccountingNew York 7698£2, AccountingNew York 7782£2, AccountingNew York 7788£3, AccountingNew York 7839£5, AccountingNew York 7902£3, AccountingNew York 7566£2, ResearchDallas 7698£2, ResearchDallas 7782£2, ResearchDallas 7788£3, ResearchDallas 7839£5, ResearchDallas 7902£3, ResearchDallas

Relational algebra operators (11) dept – emp – salgrade example (9) 7566£2, SalesChicago 7698£2, SalesChicago 7782£2, SalesChicago 7788£3, SalesChicago 7839£5, SalesChicago 7902£3, SalesChicago 7566£2, OperationsBoston 7698£2, OperationsBoston 7782£2, OperationsBoston 7788£3, OperationsBoston 7839£5, OperationsBoston 7902£3, OperationsBoston continued from last page :

Relational algebra operators (12) dept – emp – salgrade example (10) o Product (Cartesian product) DEPT has 4 records EMPX has 6 records so DEPT x EMPX has 24 records but not very useful

Relational algebra operators (13) dept – emp – salgrade example (11) o Equi-Join => product restricted to rows which have matching common domain empno salEMPX. deptno dept. deptno dnameloc 7566£2, ResearchDallas 7698£2, SalesChicago 7782£2, AccountingNew York 7788£3, ResearchDallas 7839£5, AccountingNew York 7902£3, ResearchDallas

Relational algebra operators (14) dept – emp – salgrade example (12) o Natural Join => equi-join projected with the duplicate column removed empno saldeptnodnameloc 7566£2, ResearchDallas 7698£2, SalesChicago 7782£2, AccountingNew York 7788£3, ResearchDallas 7839£5, AccountingNew York 7902£3, ResearchDallas

Basic SQL o SELECT * FROM EMP WHERE SAL > 2000; o SELECT ENAME,SAL,DEPTNO FROM EMP; o SELECT ENAME,SAL,DEPTNO FROM EMP WHERE SAL > 2000; o SELECT * FROM EMP, DEPT WHERE SAL > 2000; o SELECT * FROM EMP,DEPT WHERE SAL > 2000 AND EMP.DEPTNO = DEPT.DEPTNO; o SELECT EMPNO, SAL, DEPTNO, DNAME FROM EMP,DEPT WHERE SAL > 2000 AND EMP.DEPTNO = DEPT.DEPTNO;

Bibliography / Readings Bibliography -An Introduction to Database Systems (8 th ed.), C J Date, Addison Wesley 2004An Introduction to Database Systems -Database Management Systems, P Ward & G Defoulas, Thomson 2006Database Management Systems Readings -Introduction to SQL, McGraw-Hill/Osbourne (handout)