Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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

2 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

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

4 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.

5 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

6 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

7 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’

8 Is it an Algebra?? zWhole numbers and + - * / y5 - 3 = 2 but 3 - 5 = -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 -8 - -9 = 1 y3 * 4 = 12 and 3 * -4 = -12

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

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

11 The Relational Algebra Restrict Project Join Union Intersect Difference Division

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

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

14 EMP - table ( reduced) EmpnoEnameMgr Sal Deptno 7369SMITH7902 £800.0020 7499ALLEN7698£1,600.0030 7521WARD7698£1,250.0030 7566JONES7839£2,975.0020 7654MARTIN7698£1,250.0030 7698BLAKE7839£2,850.0030 7782CLARK7839£2,450.0010 7788SCOTT7566£3,000.0020 7839KING£5,000.0010 7844TURNER7698£1,500.0030 7876ADAMS7788£1,100.0020 7900JAMES7698 £950.0030 7902FORD7566£3,000.0020 7934MILLER7782£1,300.0010

15 Salgrade Table GradeLosalHisal 1£700.00£1,200.00 2£1,201.00£1,400.00 3£1,401.00£2,000.00 4£2,001.00£3,000.00 5£3,001.00£99,999.00

16 Restrict Subset of the Rows in a Table zRESTRICT EMP WHERE sal > 2000 empnoename mgrsaldeptno 7566JONES7839£2,975.0020 7698BLAKE7839£2,850.0030 7782CLARK7839£2,450.0010 7788SCOTT7566£3,000.0020 7839KING£5,000.0010 7902FORD7566£3,000.0020

17 Project: subset the Columns in a Table zPROJECT EMP z[EMPNO, SAL,DEPTNO] Empnosal Deptno 7369£800.0020 7499£1,600.0030 7521£1,250.0030 7566£2,975.0020 7654£1,250.0030 7698£2,850.0030 7782£2,450.0010 7788£3,000.0020 7839£5,000.0010 7844£1,500.0030 7876£1,100.0020 7900£950.0030 7902£3,000.0020 7934£1,300.0010

18 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,975.0020 7698£2,850.0030 7782£2,450.0010 7788£3,000.0020 7839£5,000.0010 7902£3,000.0020

19 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,975.002010AccountingNew York 7698£2,850.003010AccountingNew York 7782£2,450.001010AccountingNew York 7788£3,000.002010AccountingNew York 7839£5,000.001010AccountingNew York 7902£3,000.002010AccountingNew York 7566£2,975.002020ResearchDallas 7698£2,850.003020ResearchDallas 7782£2,450.001020ResearchDallas 7788£3,000.002020ResearchDallas 7839£5,000.001020ResearchDallas 7902£3,000.002020ResearchDallas

20 7566£2,975.002030SalesChicago 7698£2,850.003030SalesChicago 7782£2,450.001030SalesChicago 7788£3,000.002030SalesChicago 7839£5,000.001030SalesChicago 7902£3,000.002030SalesChicago 7566£2,975.002040OperationsBoston 7698£2,850.003040OperationsBoston 7782£2,450.001040OperationsBoston 7788£3,000.002040OperationsBoston 7839£5,000.001040OperationsBoston 7902£3,000.002040OperationsBoston

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

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

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

24 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;


Download ppt "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."

Similar presentations


Ads by Google