The 2 nd Hand Student Book Database Jon Havier High Distinction Assignment, Autumn 2007.

Slides:



Advertisements
Similar presentations
Advanced SQL Topics Edward Wu.
Advertisements

Structured Query Language (SQL)
Database Queries and Structured Query Language (SQL) J.G. Zheng May 16 th 2008.
What is a Database By: Cristian Dubon.
Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS.
Concepts of Database Management Seventh Edition
Introduction to Structured Query Language (SQL)
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Database Design Concepts INFO1408 Term 2 week 1 Data validation and Referential integrity.
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Introduction to Structured Query Language (SQL)
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Database – Part 2a Dr. V.T. Raja Oregon State University.
Inner join, self join and Outer join Sen Zhang. Joining data together is one of the most significant strengths of a relational database. A join is a query.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
INFORMATION TECHNOLOGY IN BUSINESS AND SOCIETY SESSION 16 – SQL SEAN J. TAYLOR.
ACCESS CHAPTER 1. OBJECTIVES Tables Queries Forms Reports Primary and Foreign Keys Relationship.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
Chapter 3 Single-Table Queries
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
DAY 14: ACCESS CHAPTER 1 Tazin Afrin October 03,
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
Chapter 1 Overview of Database Concepts Oracle 10g: SQL
Data Modelling – ERD Entity Relationship Diagram’s Entity Relationship Diagrams and how to create them. 1.
The Carnie_MyCareer Case Study Peter Ebeid Dane Harris Stephanie Ho Chris Zaharia Distinction Assignment, Autumn 2007 Presented by.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
ITBIS373 Database Development
IST 210: ORGANIZATION OF DATA Chapter 1. Getting Started IST210 1.
“National Electoral Division Profiles” Case Study Vincent Tang High Distinction Assignment, Autumn 2007.
SQL 101 for Web Developers 14 November What is a database and why have one? Tables, relationships, normalization SQL – What SQL is and isn’t – CRUD:
1 Intro to JOINs SQL INNER JOIN SQL OUTER JOIN SQL FULL JOIN SQL CROSS JOIN Intro to VIEWs Simple VIEWs Considerations about VIEWs VIEWs as filters ALTER.
RDBMSSection Relational DBMS DATABASE DEVELOPMENT And Franchise Colleges By MANSHA NAWAZ.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Introduction to Databases Trisha Cummings. What is a database? A database is a tool for collecting and organizing information. Databases can store information.
Using Special Operators (LIKE and IN)
Chapter 17 Creating a Database.
M1G Introduction to Database Development 2. Creating a Database.
Nitin Singh/AAO RTI ALLAHABAD 1 SQL Nitin Singh/AAO RTI ALLAHABAD 2 OBJECTIVES §What is SQL? §Types of SQL commands and their function §Query §Index.
Relational Database. Database Management System (DBMS)
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Database Management Systems.  Database management system (DBMS)  Store large collections of data  Organize the data  Becomes a data storage system.
Exploring Microsoft Access Chapter 6 Many-to-Many Relationships: A More Complex System.
ITGS Databases.
1 CSE 2337 Introduction to Data Management Access Book – Ch 1.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
1 The Information School of the University of Washington Dec 1fit advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.
An Entity Relationship (ER) Diagram is a graphic that shows the interrelationship between entities in a database.
Database Design. The process of developing database structures from user requirements for data a structured methodology Structured Methodology - a number.
Indexes and Views Unit 7.
IS 380 Introduction to SQL This lectures covers material from: database textbook chapter 3 Oracle chapter: 3,14,17.
1 PROJECT 10 DATABASE QUERIES— TEXTBOOK DATABASE Management Information Systems, 9 th edition, By Raymond McLeod, Jr. and George P. Schell © 2004, Prentice.
Database Principles Autumn 2007 High Distinction Assignment REBEL Sport Online Author: Joseph Diver.
* Database is a group of related objects * Objects can be Tables, Forms, Queries or Reports * All data reside in Tables * A Row in a Table is a record.
Logical Database Design and the Relational Model.
Jenny Jirathammakul High Distinction Assignment Database Principles Autumn, 2007 Melbourne City Toyota.
Data Modeling AND ER MODELS.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Chapter 1. Getting Started IST 210: Organization of Data IST2101.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
XP Chapter 1 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Level 2 Objectives: Understanding and Creating Table.
THE DATABASE OF MSY TECHNOLOGY PTY. LTD PRODUCT Ronald Diningrat High Distinction Assignment Autumn 2007.
The Booktopia Database
Fundamental of Database Systems
Chapter 5 Introduction to SQL.
Databases.
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Contents Preface I Introduction Lesson Objectives I-2
ICT Database Lesson 2 Designing a Database.
Presentation transcript:

The 2 nd Hand Student Book Database Jon Havier High Distinction Assignment, Autumn 2007

2 Introduction to the 2 nd hand Student Book Database 2 nd Hand Student book database simulates a DMS currently in use by Student Exchange, an online website that exchanges contact details for students to sell their books. 2 nd Hand student book is a simplified version It aims to create a nexus between sellers and buyers advertised by both parties through certain criteria’s such as book title, edition and location. This is a website familiar with many university students and helps in the purchase of course textbooks which can be very expensive

3 Student Exchange Website

4 The ERD for 2 nd Hand student books Database 2 nd Hand student Books – 4 tables Sale table is a weak entity as its primary key is borrowed from Student and textbook table

Entities and Relationships

6 1:Many relationship 1:Many relationship (1:m) occurs when one record in a table is related to multiple records in another table. An example would be one student can sell many textbooks while one textbook can only belong to one student. Therefore the seller table has a 1:m relationship with the Textbook table.

7 1:Many relationship One Student can buy many textbooks (ISBN) Student other columns dent.uts.edu.au … … etc …… Student ISBNAddate s.edu.au /01/2007 s.edu.au /01/2007 Foreign key

8 M:M relationship M:M relationship occurs when one record in a table is related to multiple records in another table and vice- versa. An example would be one student with many ISBN no’s and one ISBN with many student e- mail's. Therefore a student table has a many to many (indirect) relationship with the Sale table

9 One Student can have many ISBN and one ISBN can have many Student M:M relationship Student ISBNAddateetc nt.uts.edu.au /01/20 07 … nt.uts.edu.au /01/20 07 … nt.uts.edu.au /01/20 07 … nt.uts.edu.au /01/20 07 …

SQL Queries SQL query 1: Simple Query of a single table SQL query 2: Natural Join SQL query 3: Cross product SQL query 4: Group By SQL query 5: Sub-query SQL query 6: Cross product (Self join)

11 SQL query 1 – Simple SELECT A Select statement allows the database user to select and view a number of columns in a table or many tables with certain specific criteria. The output of the query depends on the selected columns, the tables required and the criteria applied to them. SELECT ______ FROM____________ WHERE_______ HAVING __________ GROUP BY____________ Etc.________ ;

12 SQL query 1 - Simple Show ISBN & Seller of all textbooks registered SELECT ISBN, Seller FROM Jontext2007textbook; ISBN | Seller | Etc (15 rows)

13 SQL query 2 – Natural Join A natural join combines two or more tables via a common column. The primary key of one table matches the foreign key of another table

14 SQL query 2 – Natural Join Display ISBN, seller , sellerphone & sellername of all sellers currently selling the textbook with ISBN: Select ISBN, seller , sellerphone, sellername from Jontext2007textbook natural join Jontext2007seller where ISBN = ; ISBN | Seller |Sellerphone | Sellername | | | Alberto (1 row)

15 SQL query 3 – Cross Product Version Essential a natural join but database users define the join specifically. Used for more complex joins Using dot format, a database user will specifically detail the columns which will be joined

16 SQL query 3 – Cross Product Version Display ISBN, seller , sellerphone & sellername of all sellers currently selling the textbook with ISBN: in Cross-product form Select ISBN, seller , sellerphone, sellername from Jontext2007textbook T1, Jontext2007seller T2 Where T1.Seller = T2.Seller AND ISBN = ; ISBN | Seller |Sellerphone | Sellername | | Alberto (1 row)

17 SQL query 4 – Group By A group by in a table is a function that allows certain data in a table to be collapsed into one row based on a column with the same variable Having: Similar to WHERE Uses aggregate functions in a query, having acts like a ‘where’ in determining the condition used

18 SQL query 4 – Group By Show the student name which have more than one book for sale and how many books they have for offer Select studentname, count (*) as Number_of_books from Jontext2007student natural join Jontext2007Forsale group by StudentName having count (*) > 1; Studentname | Number_of_books Alberto | 3 Bob | 3 Cameron | 4 David | 3 (4 rows)

19 SQL query 5 - Sub-query Essentially a query within a query Used to find often a single result Often used for complex queries

20 List ISBN, price of all textbooks where price is the highest SELECT ISBN, Price FROM Jontext2007textbook WHERE price >= ALL (Select price FROM Jontext2007textbook); ISBN | Price | 100 (1 rows) SQL query 5 - Sub-query

21 SQL query 6 – Self-join A self join is another version of cross join where a table is joined to its self kin order to find different rows in the table with matching elements Often for more complex queries

22 Show the books (ISBN) which are available from the same seller SELECT T1.Seller , T1.texttitle, T1.Author, T2.ISBN, T2.price FROM Jontext2007textbook T1, Jontext2007textbook T2 WHERE T1.seller = T2.Seller AND t1.ISBN < T2.ISBN; Seller | Texttitle | Author | ISBN | Price Aust. Accounting | Picker, L & Radford | | $100 (1 rows) SQL query 6 – Self-join

23 CHECK Constraints Example Check statements prevent database user from entering data which could corrupt and create inconsistency with the database or data making it not logical for its field They include entering names into date fields which should be a numerical field Avoids the possibility of Murphy’s Law ‘Things will go wrong in any given situation, if you give them a chance’ – wiki CHECK statements don’t give them that chance

24 CREATE TABLE Jontext2007textbook ( ISBNINTEGER NOT NULL, Seller VARCHAR (50) NOT NULL, TexttitleVARCHAR(100) NOT NULL, Author VARCHAR(300) NOT NULL, EditionVARCHAR(50) NOT NULL, UniversityVARCHAR(50) NOT NULL, SubjectVARCHAR(50) NULL, PriceINTEGERNOT NULL, CONSTRAINT PKtextbook PRIMARY KEY (ISBN), CONSTRAINT Price CHECK (Price > 0), CONSTRAINT University CHECK (University = 'UTS' OR University = 'UNSW' OR University = 'MACQ' OR University = 'UWS'), CONSTRAINT FKtextbook FOREIGN KEY (Seller ) REFERENCES Jontext2007Seller ON DELETE CASCADE ); CHECK Constraints Example

25 SQL Syntax for Actions Action statements are measures used to prevent the corruption of data when there is a change or a deletion of one of the records in one table. These actions correct the relating data in the other associated tables by using a ‘cascade’ effect Again avoids the possibility of Murphy’s Law ‘Things will go wrong in any given situation, if you give them a chance’ – wiki Action statements don’t give them that chance

26 SQL Syntax for Actions CREATE TABLE Jontext2007textbook ( ISBNINTEGER NOT NULL, Seller VARCHAR (50) NOT NULL, TexttitleVARCHAR(100) NOT NULL, Author VARCHAR(300) NOT NULL, EditionVARCHAR(50) NOT NULL, UniversityVARCHAR(50) NOT NULL, SubjectVARCHAR(50) NULL, PriceINTEGERNOT NULL, CONSTRAINT PKtextbook PRIMARY KEY (ISBN), CONSTRAINT Price CHECK (Price > 0), CONSTRAINT University CHECK (University = 'UTS' OR University = 'UNSW' OR University = 'MACQ' OR University = 'UWS'), CONSTRAINT FKtextbook FOREIGN KEY (Seller ) REFERENCES Jontext2007Seller ON DELETE CASCADE );

27 Creating a View Views allow database users to view a result of a statement that is used frequently without having to re-write that statement every time that view is required. This creates ease of usability, one of the benefits of a DMS system

28 An Example of Creating a View CREATE VIEW Expensivebook (Texttitle, Price, Sellername) AS SELECT Title, Expensiveprice, Expensiveseller FROM Jontext2007textbook, Jontext2007seller WHERE textbook.Seller = Seller.Sellername;

29 An Example of Querying a View Query exactly as if a table SELECT * FROM Expensivebook ; TitleExpensivepriceExpensive seller Aust. Accounting Standards 100Alberto

30 The End Any Questions?