Logical Layer The Relational Data Model + SQL. Abstraction Layers zConceptual yWhat data is held xAn Image and its meta-data xEntity-Relationship model.

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.
BACS 485—Database Management Advanced SQL Overview Advanced DDL, DML, and DCL Commands.
12-1 Copyright  Oracle Corporation, All rights reserved. What Is a View? EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
Restricting and sorting data 16 May May May Created By Pantharee Sawasdimongkol.
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.
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,
Conceptual Modelling Entity Relationship Model Overview Entities, Attributes and Relationship modelling Generating a Relational Database for an EAR 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.
ERM to SQL. Abstraction Layers Conceptual –What data is held An Image and its meta-data Entity-Relationship model (ERM) Logical –How data is organised.
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.
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.
RDB/1 An introduction to RDBMS Objectives –To learn about the history and future direction of the SQL standard –To get an overall appreciation of a modern.
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.
Relational Model Concepts. The relational model represents the database as a collection of relations. Each relation resembles a table of values. A table.
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.
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.
Subqueries.
1 Information Retrieval and Use (IRU) CE An Introduction To SQL Part 1.
IT The Relational DBMS Section 07. Relational Database Theory Using a Relational DBMS.
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 FUNDAMENTALS SQL ( Structured Query Language )
SQL- DQL (Oracle Version). 2 SELECT Statement Syntax SELECT [DISTINCT] column_list FROM table_list [WHERE conditional expression] [GROUP BY column_list]
SQL. Relating Multiple Tables Relational Database Terminology Row PK Column FK Field NULL.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Basic SQL These slides are licensed under.
FEN Introduction to the database field:  The Relational Model Seminar: Introduction to relational databases.
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.
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.
Copyright  Oracle Corporation, All rights reserved. 12 Creating Views.
An Introduction To SQL Part 2 (Special thanks to Geoff Leese)
1 Information Retrieval and Use (IRU) An Introduction To SQL Part 2.
(SQL - Structured Query Language)
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.
Copyright س Oracle Corporation, All rights reserved. 12 Creating Views.
CSCI N311: Oracle Database Programming 5-1 Chapter 15: Changing Data: insert, update, delete Insert Rollback Commit Update Delete Insert Statement –Allows.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
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
Subqueries.
What Is a View? EMPNO ENAME JOB EMP Table EMPVU10 View
Lecture 16 : The Relational Data Model
Restricting and Sorting Data
Lecture 16 : The Relational Data Model
Presentation transcript:

Logical Layer The Relational Data Model + SQL

Abstraction Layers zConceptual yWhat data is held xAn Image and its meta-data xEntity-Relationship model (ERM) zLogical yHow data is organised in storage xBlock and Directory structure xTables, keys zPhysical yHow data is stored in bits xJPEG as a stream of bytes xA Database as files and records stored in a DBMS-specific format Abstraction Realisation (Refinement Reification) (Reverse Engineering) (Engineering, Model-Driven development

The Relational Data Model zThe Theory underlying Relational Databases – Access, Oracle, MySQL.. zE.F Codd A Relational Data Model for Large Shared Data Banks (1970) 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

EMP-DEPT example (from SQL workbook) Two relations: Department : DEPTDEPT Employee : EMPEMP

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

EMP - table 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,

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

Relations are everything zThere is only one data structure in the relational data model - the relation yEvery relation in a database must have a distinct name. yEvery column in a relation must have a distinct name within the relation. yAll entries in a column must be of the same kind yThe ordering of columns in a relation is not significant. yEach row in a relation must be distinct xLeads to Primary Key in a Relational Database yThe ordering of rows is not significant. yEach cell or column/row intersection in a relation should contain only a so-called atomic value.

Relational Algebra zA group of operations on relations which yield only other relations – “Closed” yA single tuple (row) is a relation yA single value is also a relation zBase operations yRESTRICT, PROJECT, PRODUCT zConvenience operations yEQUI-JOIN, (Natural) JOIN, Outer Joins zSet operations yUNION, INTERSECTION, DIFFERENCE, DIVISION

The Relational Algebra Restrict Project Product Union Intersect

SQL (SeQueL) zThere are a number of languages for manipulating relations, but the one most commonly implemented is SQL zSQL zSQL ybetter support for Algebraic operations zSQL Post-Relational yrow and column types, stored procedures, triggers, references, large objects

SQL zDATA MANIPULATION (DML) - factbase yQUERY xSELECT yUPDATE xUPDATE xDELETE xINSERT zDATA DEFINITION (DDL) -schema yCREATE, ALTER, DROP zDATA CONTROL (DCL) - access control yGRANT,REVOKE

RESTRICT: SELECT * FROM EMP WHERE sal > 2000 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,

Project: Select Empno,Mgr,Deptno from Emp 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,

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, Restrict - Project: Select Empno,Mgr,Deptno from Emp where sal > 2000;

Restrict - Project: Select Empno,Mgr,Deptno from Emp where Sal > 2000 and Sal < 3000; 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,

Some queries to write: zhttp:// l/queryemp.phphttp:// l/queryemp.php zList the names of the employees whose manager is 7698 zList the empnos of the employees in Department no 20 whose salary is over $2500

EmpnoMgrDeptno DeptnoDnameLocation 10AccountingNew York 20ResearchDallas 30SalesChicago 40OperationsBoston Product: Select * from EmpX, Dept; EmpnoMgrDeptno DnameLocation AccountingNew York ResearchDallas SalesChicago OperationsBoston AccountingNew York ResearchDallas SalesChicago OperationsBoston AccountingNew York ResearchDallas SalesChicago OperationsBoston

Product : zDEPT has 4 records zEMPX has 3 records zso DEPT x EMPX has 12 records zbut not very useful

EmpnoMgrDeptnoDeptnoDnameLocation AccountingNew York ResearchDallas SalesChicago OperationsBoston AccountingNew York ResearchDallas SalesChicago OperationsBoston AccountingNew York ResearchDallas SalesChicago OperationsBoston Product – Project - Restrict Select * from EmpX,Dept where Emp.Deptno=Dept.Deptno;

EmpnoMgrDeptnoDeptnoDnameLocation AccountingNew York ResearchDallas SalesChicago OperationsBoston AccountingNew York ResearchDallas SalesChicago OperationsBoston AccountingNew York ResearchDallas SalesChicago OperationsBoston Product – Project - Restrict Select * from EmpX natural join Dept; Restrict – Project – Product – Restrict – Project : Select Empno,Mgr,Deptno,Dname from Emp Natural Join Dept where Sal > 2000 and Sal < 3000;

Join queries zList the names of all staff in department number 10

SQL Functions vary with RDBMS zSTRINGS yLIKE, CONCAT, SUBSTR… zDATE ySYSDATE.. zSTATISTICAL FUNCTIONS yCOUNT, AVG, MIN, MAX, SUM yGENERATE AGGREGATE VALUES ySELECT SUM(sal) FROM emp; xshows total salary over all emps

zSorting Rows (tuples) ySelect ename, sal from emp order by sal; zGrouping Rows ySelect deptno, count(*) from emp group by deptno; zLimiting the number of Rows ySelect ename, sal from emp order by sal desc limit 1;

RDMS zRelational Database Management System yMaps Relations and values into the Physical Layer yInterprets SQL statements and executes the requested updates on the physical data yControls access to data, recovery from errors..

MySQL yFree – pay for support yCommand line interface or use PHPMyAdmin yInstalled for student use on shares – usual Unix login yPersonal copy easily be installed yMultiple databases can be created – you get just one ySeveral different file systems for physical storage (ISAM, INNODB) yISAM xThree files per table definition (schema).FRM Data.MYD Index.MYI

What would you expect to see at the physical layer?

Department Table data file ASCII String length Record header Dept no Big or Little Endian?

Learning SQL zWorkbook yMySQL, Oracle and MS Access yWe will be using MySQL with PHP yhttp:// zSQL/PHP Textbook yChapter 10 of Welling and Thomson