Relational Database Systems Higher Information Systems Advanced Implementation in MySQL/PHP.

Slides:



Advertisements
Similar presentations
Relational Database Systems Higher Information Systems Advanced Implementation in Microsoft Access.
Advertisements

Organisation Of Data (1) Database Theory
Relational Database Systems Higher Information Systems Advanced Implementation in Filemaker Pro.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
Database Systems: Design, Implementation, and Management Tenth Edition
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Query by example (based on notes by Silberchatz,Korth, and Sudarshan.
Introduction to Structured Query Language (SQL)
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
Relational Databases What is a relational database? What would we use one for? What do they look like? How can we describe them? How can you create one?
CORE 2: Information systems and Databases STORAGE & RETRIEVAL 2 : SEARCHING, SELECTING & SORTING.
Software Development Unit 2 Databases What is a database? A collection of data organised in a manner that allows access, retrieval and use of that data.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
2.3 Organising Data for Effective Retrieval
ASP.NET Programming with C# and SQL Server First Edition
Chapter 3 Single-Table Queries
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE) Datalog.
Web Application Development. Tools to create a simple web- editable database QSEE MySQL (or PHPMyAdmin) PHP TableEditor.
1 MySQL and phpMyAdmin. 2 Navigate to and log on (username: pmadmin)
Databases & Database Driven Websites Notes
Introduction to Microsoft Access 2003 Mr. A. Craig Dixon CIS 100: Introduction to Computers Spring 2006.
10 May Microsoft Access 2010 Relational databases’ program Part of the Microsoft Office package Administer relational database Update database through.
Database: SQL and MySQL
Slide 1 Standard Grade Computing Databases. Slide 2 Standard Grade Computing Definitions DatabaseA database is a structured collection of similar information.
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE)
M1G Introduction to Database Development 2. Creating a Database.
Access Project 3 Notes. Introduction Maintaining the Database  Modifying the data to keep it up-to-date Restructure the Database  To change the database.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Part II. Query Types On the design query table pane, right click and the cascading window will appear.
Ch Determine the output displayed from procedures Lab sheet 10.4.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Database Management Systems.  Database management system (DBMS)  Store large collections of data  Organize the data  Becomes a data storage system.
Pasewark & Pasewark 1 Access Lesson 3 Creating Queries Microsoft Office 2007: Introductory.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Source: Database System Concepts, Silberschatz etc Edited: Wei-Pang Yang, IM.NDHU, Introduction to Database CHAPTER 5 Other Relational Languages.
Access Chapter 3-Obtaining Answers to Your Data Questions.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
Session 1 Module 1: Introduction to Data Integrity
9-1 © Prentice Hall, 2007 Topic 9: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Exploring Microsoft Access Chapter 5 One-to-Many Relationships: Subforms and Multiple Table Queries.
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
Software. Because databases can get very big, it is important to decide exactly what is going to be stored in each field. Fields can be text, number,
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 5: SQL I Rob Gleasure robgleasure.com.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
VOCAB REVIEW. A field that can be computed from other fields Calculated field Click for the answer Next Question.
Database (Microsoft Access). Database A database is an organized collection of related data about a specific topic or purpose. Examples of databases include:
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
DAY 20: ACCESS CHAPTERS 5, 6, 7 Larry Reaves October 28,
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
N5 Databases Notes Information Systems Design & Development: Structures and links.
Microsoft Office Access 2010 Lab 3
Chapter 5 Introduction to SQL.
Databases.
Relational Database Design
Paul Jacobs The iSchool University of Maryland Thursday, Oct. 5, 2017
Lesson Objectives Aims You should know about: 1.3.2: (a) indexing (d) SQL – Interpret and Modify (e) Referential integrity (f) Transaction processing,
Presentation transcript:

Relational Database Systems Higher Information Systems Advanced Implementation in MySQL/PHP

Developing a solution Tables Queries User Views Navigation

Introducing SQL Relational database management systems (RDBMSs) are based on a data definition language called Structured Query Language or SQL (often pronounced sequel). MySQL takes its name from SQL.

Introducing SQL SQL is a data definition language CREATE DATABASE `DVD Rentals` CREATE TABLE Member( `Member Number` integer, Name varchar(30), Address varchar(50), `Post Code` varchar(7), `Telephone Number` varchar(11))

Introducing SQL SQL is also a data manipulation language INSERT INTO Member VALUES (`233`, `Jo Soap`, `1 Getting Close`, `IS99 2QZ`, `123456`) SELECT * FROM Member WHERE `Member Number` BETWEEN 1 and 250 ORDER BY `Member Number` DESC DELETE FROM Member WHERE `Member Number` > 500

phpMyAdmin A graphical user interface for MySQL

phpMyAdmin Viewing a table definition

phpMyAdmin Adding a record

phpMyAdmin Selecting records

phpMyAdmin Viewing selected records

phpMyAdmin Viewing selected records

Referential Integrity For the database to work properly, it is essential to guarantee that a foreign key always refers to a record which exists in the other table. This is called referential integrity. For example, an entry in the Loan table can only refer to an existing record in the Member table, because a loan can only be made by a member.

Referential Integrity MySQL has no internal facility to maintain referential integrity (with the default MyISAM table type) - instead, the databases interface must be designed in such a way that a check is made on any value entered to ensure it is valid. Usually this is done by using a list on a web page to display the available choices for a field value from which the user may make a selection.

Validation: Presence Check

Validation: Range Check Range checking is performed by the interface Use PHP scripting to check numeric values

Validation: Restricted Choice Check

Validation: Default Value

Formatting All formatting of data for output is done using PHP functions e.g. printf

Queries Searching Sorting Calculations All searching, sorting and calculation queries are performed using an SQL expression string

Searching Searching is the process of selecting records from a table or combination of tables. To perform the query, three items must be identified: Which fields will be used to identify the records required? Which tables are required to produce the data required? What are the criteria for identifying the records required?

Search 1: Single Condition Identify the names and telephone numbers of club members with Member Number over 1000 SELECT FORENAME, SURNAME, `TELEPHONE NUMBER` FROM MEMBER WHERE `MEMBER NUMBER` > 1000

Search 1: Single Condition The asterisk * symbol can be used in an expression string to extract all fields from a table SELECT * FROM MEMBER WHERE `MEMBER NUMBER` > 1000

Search 2: Multiple Conditions (AND) Identify the names and telephone numbers of club members with Surnames beginning with M and Member Number over 1000 SELECT FORENAME, SURNAME, `TELEPHONE NUMBER` FROM MEMBER WHERE SURNAME LIKE M* AND `MEMBER NUMBER` > 1000

Search 3: Multiple Conditions (OR) Identify the names and telephone numbers of club members with Surnames beginning with M or N SELECT FORENAME, SURNAME, `TELEPHONE NUMBER` FROM MEMBER WHERE SURNAME LIKE M* OR SURNAME LIKE N*

Search 4: More than one table Identify the names of club members who rented a DVD in August 2005 In order to extract the related records from each table, a join operation is performed in SQL This will combine those records from each table which have a corresponding record in the other table into a single set of related records (called an answer set) The keyword used to perform this is INNER JOIN

Search 4: More than one table Identify the names of club members who rented a DVD in August 2005 SELECT FORENAME, SURNAME, `DATE HIRED` FROM (MEMBER INNER JOIN LOAN) ON `MEMBER.MEMBER NUMBER`=`LOAN.MEMBER NUMBER` WHERE `DATE HIRED` LIKE */8/2005

Search 5: More than two tables Identify the names of members who have rented Shrek This time all four tables are required: Member, Loan, DVD and Film. A nested INNER JOIN statement must be performed to combine these together into a single answer set

Search 5: More than two tables Identify the names of members who have rented Shrek SELECT `FORENAME`, `SURNAME`, `TITLE` FROM (((MEMBER INNER JOIN LOAN ON MEMBER.MEMBER NUMBER=LOAN.MEMBER NUMBER) INNER JOIN DVD ON LOAN.DVD CODE = DVD.DVD CODE) INNER JOIN FILM ON DVD.FILM CODE = FILM.FILM CODE) WHERE `TITLE` = SHREK

Search 6: Dealing with duplicates List those members who have rented Shrek or Finding Nemo SELECT `FORENAME`, `SURNAME`, `TITLE` FROM (((MEMBER INNER JOIN LOAN ON MEMBER.MEMBER NUMBER=LOAN.MEMBER NUMBER) INNER JOIN DVD ON LOAN.DVD CODE = DVD.DVD CODE) INNER JOIN FILM ON DVD.FILM CODE = FILM.FILM CODE) WHERE `TITLE` = SHREK OR `TITLE` = FINDING NEMO

Search 6: Dealing with duplicates The Group By option is used to eliminate duplicate results SELECT `FORENAME`, `SURNAME`, `TITLE` FROM (((MEMBER INNER JOIN LOAN ON MEMBER.MEMBER NUMBER=LOAN.MEMBER NUMBER) INNER JOIN DVD ON LOAN.DVD CODE = DVD.DVD CODE) INNER JOIN FILM ON DVD.FILM CODE = FILM.FILM CODE) WHERE `TITLE` = SHREK OR `TITLE` = FINDING NEMO GROUP BY *

Sorting To perform a sort, two items must be identified: Which field (or fields) will be used to decide the order of records? For each field selected, will the order of sorting be ascending or descending?

Sorting To produce a list of people with the tallest first, the records would be sorted in descending order of height. To produce a list of people with youngest first, the records would be sorted in ascending order of age. A very common way of ordering records relating to people is in alphabetical order. To achieve alphabetical ordering requires the records to be sorted in ascending order of surname.

Complex Sorting A complex sort involves more than one sort condition involving two or more fields. To achieve telephone book order, the name is sorted in ascending order of surname, then ascending order of forename. In this case, the Surname field is the primary sort key, and the Forename field is the secondary sort key.

Sorting SELECT FORENAME, SURNAME FROM MEMBER WHERE `MEMBER NUMBER` > 1000 ORDER BY SURNAME, FORENAME SELECT FORENAME, SURNAME FROM MEMBER WHERE `MEMBER NUMBER` > 1000 ORDER BY `MEMBER NUMBER` DESC

Calculations Horizontal calculations are often known as calculated fields, and vertical calculations are known as summary fields.

Functions (MySQL)

Functions (PHP)

Working with Dates to search for all DVDs rented in the last week, you would use the expression SELECT * FROM LOAN WHERE DATEDIFF(CURDATE(),`DATE HIRED`) < 7 to calculate a persons age in years from their date of birth, you would use the expression SELECT (YEAR(CURDATE()) – YEAR(`DATE OF BIRTH`) – (RIGHT(CURDATE(),5)<RIGHT(`DATE OF BIRTH`,5)) AS AGE

Parameterised Queries

User Views User views are created using forms and reports. A form or report is usually based on a query which selects the required fields from the appropriate tables, sorting the results if necessary, and performing any horizontal calculations. In a MySQL application, all output is generally in the form of a web page.

Report Structure

Summary Information Sumto add values to give a total, e.g. Total Cost of DVD Rentals last month Averageto find an average value, e.g. Average Cost of Hire per DVD Countto count the number of records found, e.g. Number of DVDs rented per member Maximumto find the highest value, e.g. Highest number of rentals per DVD (to find the most popular DVD) Minimumto find the lowest value, e.g. Lowest number of rentals per member

Summary Information In a MySQL application, the aggregate functions SUM, AVG, COUNT, MAX and MIN can be used in an SQL expression string to produce summary information for a set of extracted records However, certain summary information, such as page totals, would have to be programmed using PHP (e.g. counting the number of records being displayed)

Scripting In a MySQL application, all navigation and user interface features are implemented using scripting $result Forename, Surname FROM Member"); while ( $row = mysql_fetch_array($result) ) { $forename = $row["Forename"]; $surname = $row["Surname"]; echo(" $forename $surname "); }

Macros