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.

Slides:



Advertisements
Similar presentations
Copyright  Oracle Corporation, All rights reserved. 3 Displaying Data from Multiple Tables.
Advertisements

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.
1Eyad Alshareef Enhanced Guide to Oracle 10g Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Extended SQL & The Relational Calculus.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
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.
Logical Layer The Relational Data Model + SQL. Abstraction Layers zConceptual yWhat data is held xAn Image and its meta-data xEntity-Relationship model.
Session 3: SQL (B): Parts 3 & 4 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram.
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.
CS 380 Introduction to Database Systems (Chapter 5: The Relational Data Model and Relational Database Constraints)
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.
© Pearson Education Limited, Chapter 2 The Relational Model Transparencies.
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. Data Manipulation Language (DML)
4-1 Copyright  Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Basic Relational Algebra These slides.
Dr. Philip Cannata 1 Programming Languages Prolog Part 3 SQL & Prolog.
Lecture 8 Database Theory & Practice (2) : The Relational Data Model UFCEKG-20-2 Data, Schemas & Applications.
Displaying Data from Multiple Tables (Join). EMPNO DEPTNO LOC NEW YORK CHICAGO NEW YORK DALLAS.
MSc IT UFIE8K-15-M Data Management Prakash Chatterjee Room 3P16
2 Writing Basic SELECT Statements. 1-2 Copyright  Oracle Corporation, All rights reserved. Capabilities of SQL SELECT Statements Selection Projection.
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.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
SQL- DQL (Oracle Version). 2 SELECT Statement Syntax SELECT [DISTINCT] column_list FROM table_list [WHERE conditional expression] [GROUP BY column_list]
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Basic SQL These slides are licensed under.
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.
Copyright  Oracle Corporation, All rights reserved. Introduction.
SQL: Part 1 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram. Not for commercial.
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)
The Relational Model Pratt & Adamski, Chapter 2. Relational Algebra zProject zSelect zJoin z Union z Intersect z Subtract z Product z Division.
Copyright س Oracle Corporation, All rights reserved. I Introduction.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Relational State Assertions These slides.
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.
Copyright س Oracle Corporation, All rights reserved. 12 Creating Views.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
Displaying Data from Multiple Tables (Join) Displaying Data from Multiple Tables (Join) Displaying Data from Multiple Tables (Join Displaying Data from.
SQL Statements SELECT INSERTUPDATEDELETECREATEALTERDROPRENAMETRUNCATECOMMITROLLBACKSAVEPOINTGRANTREVOKE Data Retrieval Language (DRL) Data Retrieval Language.
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.
Relational Normalization Theory
COMP3017 Advanced Databases
Displaying Data from Multiple Tables
Displaying Data from Multiple Tables
(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:

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 DBMSs depart from the basic model

Components zThe concepts available to represent the UoD yRelations (tables) of yTuples (rows), of yColumns (fields) containing values drawn from a Domain zBase Relations - facts zDerived Relations - yRelations constructed by extracting, combining base relations

Relation DeptnoDnameLoc 10AccountingNew York 20ResearchDallas 30SalesChicago 40OperationsBoston Relation tuple Column (field) domain string city name general specific integer 0<int<99

Relations There is only one data structure in the relational data model - the relation: Every relation in a database must have a distinct name. Every column in a relation must have a distinct name within the relation. All entries in a column must be of the same kind. The ordering of columns in a relation is not significant. Each row in a relation must be distinct. The ordering of rows is not significant. Each cell or column/row intersection in a relation should contain only a so-called atomic value.

Primary Keys, Foreign Keys and Domains Each relation must have a primary key. This is to enforce the property that duplicate rows are forbidden in a relation. A primary key is one or more columns of a table whose values are used to uniquely identify each of the rows in a table. Foreign keys are the means of interconnecting the data stored in a series of disparate tables. A foreign key is a column or group of columns of some table which draws its values from the same domain as the primary key of some related table in the database. Domains are pools of values from which actual values appearing in the columns of a table are drawn. A special character is used in relational systems to indicate incomplete or unknown information - the character null. This character which is distinct from zero or space is particularly useful in the context of primary-foreign key links

Two approaches to defining a derived relation zRelational Algebra zDefine a new, derived relation as a sequence of operations on Relations zBased on operational algebra z Relational Calculus z Defines a new, derived relation as a proposition which is true for every tuple in the new table z Based on predicate calculus

Algebra?? zAlgebra: x + 6 = 10 - what’s x? zAn Algebra: ya SET of values defined by INTENSION xe.g. whole numbers - 0,1,2,3,.. yOPERATORS which combine values to compute new values xe.g. + * - / - (4+5)*6 = 120 yOperators can only produce values in the original set - ‘closure’

Is it an Algebra?? zWhole numbers and + - * / y5 - 3 = 2 but = -2 y 6/3 = 2 but 6/4 = 1.5 zSo not an algebra ycan redefine / as remainder ye.g 6/4 = 1 - then / OK zIntegers ( +ve and -ve) and + - * y8 - 9 = -1 and = 1 y3 * 4 = 12 and 3 * -4 = -12

More Algebra zOperators act on different number of values y1 unary - y2 - + * / zOrder may matter y2 + 3 = ybut 6/3 not = 3/6 zBrain teazer - make 13 from 2,3,5,7 y( (3 * 7) + 5 ) /2 = 13

Relational Algebra zBase operations yRESTRICT, PROJECT, PRODUCT zConvenience operations yEQUI-JOIN, (Natural) JOIN, Outer Joins zSet operations yUNION, INTERSECTION, DIFFERENCE, DIVISION

The Relational Algebra Restrict Project Join Union Intersect Difference Division

EMP-DEPT example Three relations: Department : DEPT Employee : EMP Salary Grade : SALGRADE

DEPT Table deptnodnamelocation 10AccountingNew York 20ResearchDallas 30SalesChicago 40OperationsBoston

EMP - table ( reduced) EmpnoEnameMgr Sal Deptno 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,

Salgrade Table GradeLosalHisal 1£700.00£1, £1,201.00£1, £1,401.00£2, £2,001.00£3, £3,001.00£99,999.00

Restrict Subset of the Rows in a Table zRESTRICT EMP WHERE sal > 2000 empnoename mgrsaldeptno 7566JONES7839£2, BLAKE7839£2, CLARK7839£2, SCOTT7566£3, KING£5, FORD7566£3,

Project: subset the Columns in a Table zPROJECT EMP z[EMPNO, SAL,DEPTNO] Empnosal Deptno 7369£ £1, £1, £2, £1, £2, £2, £3, £5, £1, £1, £ £3, £1,

Restrict-Project RESTRICT EMP WHERE SAL >2000 PROJECT EMP[EMPNO, SAL, DEPTNO] Could you reverse these operations - always? ( project then restrict?) call this EMPX empnosaldeptno 7566£2, £2, £2, £3, £5, £3,

Product: Combine each row of one table with each row of the other: PRODUCT DEPT with EMPX empnosal EMPX. DEPT. DnameLoc Deptno Depno 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

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

Product : zDEPT has 4 records zEMPX has 6 records zso DEPT x EMPX has 24 records zbut not very useful

Equi-Join : Product restricted to rows which have matching common domain Empno sal EMPX. Dept. Dname Loc DeptnoDeptno 7566£2, ResearchDallas 7698£2, SalesChicago 7782£2, AccountingNew York 7788£3, ResearchDallas 7839£5, AccountingNew York 7902£3, ResearchDallas

Natural Join: Equi-join projected with the duplicate column removed empnosal deptnodnameloc 7566£2, ResearchDallas 7698£2, SalesChicago 7782£2, AccountingNew York 7788£3, ResearchDallas 7839£5, AccountingNew York 7902£3, ResearchDallas

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