The Booktopia Database

Slides:



Advertisements
Similar presentations
Advanced SQL (part 1) CS263 Lecture 7.
Advertisements

Session 2Introduction to Database Technology Data Types and Table Creation.
COMP 3715 Spring 05. Working with data in a DBMS Any database system must allow user to  Define data Relations Attributes Constraints  Manipulate data.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
DT211 Stage 2 Databases Lab 1. Get to know SQL Server SQL server has 2 parts: –A client, running on your machine, in the lab. You access the database.
A Guide to SQL, Seventh Edition. Objectives Understand, create, and drop views Recognize the benefits of using views Grant and revoke user’s database.
Case study Lisa’s Bookstore IST210.
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
Relational Database Concepts. Let’s start with a simple example of a database application Assume that you want to keep track of your clients’ names, addresses,
The 2 nd Hand Student Book Database Jon Havier High Distinction Assignment, Autumn 2007.
CODD’s 12 RULES OF RELATIONAL DATABASE
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Fundamentals, Design, and Implementation, 9/e CPE 481 Database Processing Chapter 6 Structured Query Language (SQL) Instructor:Suthep Madarasmi, Ph.D.
Final Exam Guide PHP NOTE: PHP CODE WILL BE BLUE, HTML IS BLACK EXAMPLE
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
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:
RDBMSSection Relational DBMS DATABASE DEVELOPMENT And Franchise Colleges By MANSHA NAWAZ.
Slide 1 Chapter 7 – Part 1 Data Definition Language & Data Manipulation Language.
Chapter 5: Part 1: DDL STRUCTURED QUERY LANGUAGE (SQL)
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
CSC 240 (Blum)1 Introduction to Data Entry, Queries and Reports.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
DAT602 Database Application Development Lecture 2 Review of Relational Database.
CS499 Project #3 XML mySQL Test Generation Members Erica Wade Kevin Hardison Sameer Patwa Yi Lu.
CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints.
1 SQL III CIS2450 Advanced Programming Concepts. 2 The Join Operation It is one of the most important features of a relational system that it allows you.
CHAPTER 1 – INTRODUCTION TO ACCESS Aliya Farheen March 5, 2014.
IS 380 Introduction to SQL This lectures covers material from: database textbook chapter 3 Oracle chapter: 3,14,17.
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
Database Principles Autumn 2007 High Distinction Assignment REBEL Sport Online Author: Joseph Diver.
1 MySQL and SQL. 2 Topics  Introducing Relational Databases  Terminology  Managing Databases MySQL and SQL.
* 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.
Slide 1 Chapter 7 – Part 3 Stored Procedure, Function &Trigger.
BTM 382 Database Management Chapter 8 Advanced SQL Chitu Okoli Associate Professor in Business Technology Management John Molson School of Business, Concordia.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
LEC-8 SQL. Indexes The CREATE INDEX statement is used to create indexes in tables. Indexes allow the database application to find data fast; without reading.
THE DATABASE OF MSY TECHNOLOGY PTY. LTD PRODUCT Ronald Diningrat High Distinction Assignment Autumn 2007.
Database Constraints ICT 011. Database Constraints Database constraints are restrictions on the contents of the database or on database operations Database.
Database Constraints Ashima Wadhwa. Database Constraints Database constraints are restrictions on the contents of the database or on database operations.
ER Diagrams and Relational Model CS 174a (Winter 2015)
How to: SQL By: Sam Loch.
Chapter 6: Integrity (and Security)
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
CS 3630 Database Design and Implementation
Foreign Keys Local and Global Constraints Triggers
LINQ to DATABASE-2.
CPSC-310 Database Systems
INFO/CSE 100, Spring 2005 Fluency in Information Technology
STRUCTURED QUERY LANGUAGE
SQL LANGUAGE and Relational Data Model TUTORIAL
5.02 Understand database queries, forms, and reports used in business.
LINQ to DATABASE-2.
Creating Tables & Inserting Values Using SQL
SQL DATA CONSTRAINTS.
Data Management Innovations 2017 High level overview of DB
SQL-1 Week 8-9.
Database Processing: David M. Kroenke’s Chapter Seven:
Lecture 3 Finishing SQL
Advanced Database Concepts: Reports & Views
CMPE/SE 131 Software Engineering March 9 Class Meeting
Chapter 4 Introduction to MySQL.
Indexes and more Table Creation
CPSC-608 Database Systems
SQL (Structured Query Language)
Presentation transcript:

The Booktopia Database Designed By: Romana Chandra High Distinction Assignment- Autumn, 2007

Introduction to the Booktopia Database Booktopia is an online bookstore, similar to amazon. The contents of the database would include information regarding books, authors, customers and their purchases. Booktopia hopes to be able to expand its business from selling only books, to selling a variety of items, through the development of a better structured database and improved technologies.

The ERD for the Booktopia Database…

Many to Many Relationship (1) Many customers can purchase many books. The table BDbasket below illustrates this many to many relationship Orderno BookID Price Total quantity customer ID PMT status 231 B9 17.95 89.75 5 C1 P 232 B8 20.66 1 C3 233 B1 35.9 2 C5 Null 234 B3 26.95 C4 235 B4 22.45

Many to Many Relationship (2) Many authors exist and each author can write more than one book, many authors write many books. This is illustrated by the table: BDbookauth RecordNo authorID BookID 1 A1 B1 2 B2 3 A2 B3 4 A3 B4 5 A4 6 A5 7 A6 B5 8 A7 9 A8 10 A9 B6 11 A10 B7 12 A11 B8 13 A12 14 A13 B9 15 A14 B10 16 A15

Queries…

A simple query of a single table… List all of the books which are available. Select * from BDinfo where Availability ='Y'; isbn | bookid | title | format | price | availability ------------+--------+----------------------------------------+-----------+-------+-------------- 1844762947 | B1 | Vegetarian Soups | Paperback | 17.95 | Y 1845973909 | B3 | Vegetarian Food For Friends | Paperback | 26.95 | Y 1416948368 | B4 | Cocktail Therapy | Hardcover | 22.45 | Y 811857301 | B5 | Art of Terrior | Hardcover | 35.96 | Y 1844030571 | B7 | 100 Great Risottos | Hardcover | 22.50 | Y 1580402631 | B8 | One Pot Meals For People With Diabetes | Paperback | 20.66 | Y 754816796 | B9 | Welsh Heritage Food and Cooking | Hardcover | 17.95 | Y 811854841 | B10 | Blue Ribbon USA | Hardcover | 25.16 | Y (8 rows)

A query which uses the words ‘natural join’ List all the BookIDs’ with their corresponding Author’s. Select * from BDbookauth natural join BDauthor; authorid | recordno | bookid | authorfname | authorlname ----------+----------+--------+-------------+------------- A1 | 1 | B1 | Anne | Sheasby A1 | 2 | B2 | Anne | Sheasby A2 | 3 | B3 | Jane | Noraika A3 | 4 | B4 | Leanne | Shear A4 | 5 | B4 | Tracey | Toomey A5 | 6 | B4 | Neryl | Walker A6 | 7 | B5 | George | Rose A7 | 8 | B5 | Rod | Smith A8 | 9 | B5 | Jess | Jackson A9 | 10 | B6 | Mitchell | Vollstedt A10 | 11 | B7 | Valentina | Harris A11 | 12 | B8 | Nancy | Baggett A12 | 13 | B8 | Ruth | Glick A13 | 14 | B9 | Annette | Yates A14 | 15 | B10 | John | Margolies A15 | 16 | B10 | Georgia | Orcutt (16 rows)

The cross product equivalent to the ‘natural join’ query above… For the previous query, generate the same table using the cross product method. Select BDauthor.authorid ,RecordNo, BookId,AuthorFname, AuthorLname from BDbookauth, BDauthor where BDbookauth.authorid = BDauthor.authorid; authorid | recordno | bookid | authorfname | authorlname ----------+----------+--------+-------------+------------- A1 | 1 | B1 | Anne | Sheasby A1 | 2 | B2 | Anne | Sheasby A2 | 3 | B3 | Jane | Noraika A3 | 4 | B4 | Leanne | Shear A4 | 5 | B4 | Tracey | Toomey A5 | 6 | B4 | Neryl | Walker A6 | 7 | B5 | George | Rose A7 | 8 | B5 | Rod | Smith A8 | 9 | B5 | Jess | Jackson A9 | 10 | B6 | Mitchell | Vollstedt A10 | 11 | B7 | Valentina | Harris A11 | 12 | B8 | Nancy | Baggett A12 | 13 | B8 | Ruth | Glick A13 | 14 | B9 | Annette | Yates A14 | 15 | B10 | John | Margolies A15 | 16 | B10 | Georgia | Orcutt (16 rows)

A query involving a “Group by”, perhaps also with a “HAVING”… Report the total value of books for customers that have paid for more than one book Select customerid, SUM(total) as paidtotal from BDbasket where pmtstatus='P' group by customerid having count(customerid)>1; customerid | paidtotal ------------+----------- C3 | 43.11 (1 row)

A query which uses a sub query… Report all book titles which have a price that is greater than the average price for all books. Select title, price from BDinfo where price> (Select AVG(price) from BDinfo); title | price -----------------------------+------- Vegetarian Food For Friends | 26.95 Art of Terrior | 35.96 Blue Ribbon USA | 25.16 (3 rows)

A cross product which cannot be implemented using the words “natural join” (e.g. self join)… Show the Author ID of all the authors that wrote B10 with A14, inclusive. Select auth1.authorid, auth2.authorid, auth2.bookid from BDbookauth auth1, BDbookauth auth2 where auth1.authorid = 'A14' and auth1.bookid = auth2.bookid; authorid | authorid | bookid ----------+----------+-------- A14 | A14 | B10 A14 | A15 | B10 (2 rows)

Examples of CHECK statements… ISBN is a unique 10 digit number. Need to make sure the database does not accept anything over 10 digits. Used the following check statement as a constraint: CHECK ((ISBN>0000000001) AND (ISBN<10000000000)),

Another CHECK statement… Book Availability Can be either ‘Y’ for Yes Or ‘N’ for No Database needs to make sure that no other code is accepted as a result. Check statement will be: CHECK ((Availability='Y') or (Availability='N'))

The use of SQL action statements CREATE TABLE BDbasket ( Orderno INTEGER NOT NULL UNIQUE, BookID VARCHAR(3) NOT NULL UNIQUE, Price DECIMAL(5,2) NOT NULL, Total DECIMAL(5,2) NOT NULL CHECK ((Total>=Price)), Quantity INTEGER NOT NULL, CustomerID VARCHAR(3) NOT NULL, PmtStatus CHAR(1) CHECK ((PmtStatus='P') or (PmtStatus=Null)), CONSTRAINT BDbasketPK_Invalid_Orderno PRIMARY KEY (Orderno), CONSTRAINT BDbasket1_FK FOREIGN KEY (BookID) REFERENCES BDinfo ON UPDATE CASCADE ON DELETE CASCADE, CONSTRAINT BDbasket2_FK FOREIGN KEY (CustomerID) REFERENCES BDcustomer ON DELETE CASCADE );

Using a View in SQL… Suppose we want to obtain a comprehensive report such as the following: Show the Book ID, Title and Author ID of all the available books from the first 9 records inclusive. The query would be: Select bookid, title, authorid from BDinfo natural join BDbookauth where availability=‘Y’ and recordno>10;

Views Continued… The following output is obtained: bookid | title | authorid --------+----------------------------------------+---------- B7 | 100 Great Risottos | A10 B8 | One Pot Meals For People With Diabetes | A11 B8 | One Pot Meals For People With Diabetes | A12 B9 | Welsh Heritage Food and Cooking | A13 B10 | Blue Ribbon USA | A14 B10 | Blue Ribbon USA | A15 (6 rows)

Views continued… Suppose this query is required again at a later time, It would be rather inconvenient to type out such a long query all the time. Here is where the use of views come in. A view is basically saving a particular query on the database as a particular name.

Views Continued… To create the view: Applying this to our query, The syntax to create a view is CREATE VIEW name AS query. This will save the query string query to the database under the name name. Applying this to our query, Create view booktopiaview as Select bookid, title, authorid from BDinfo natural join BDbookauth where availability='Y' and recordno>10;

Views Continued… Now the view has been created, we can check using \dv that it exists List of relations Name | Type | Owner ---------------------------------+------+---------- booktopiaview | view | rochandr

Select * from Booktopiaview; Views continued… We can now use the view at any time simply by using a normal select query: Select * from Booktopiaview; bookid | title | authorid --------+----------------------------------------+---------- B7 | 100 Great Risottos | A10 B8 | One Pot Meals For People With Diabetes | A11 B8 | One Pot Meals For People With Diabetes | A12 B9 | Welsh Heritage Food and Cooking | A13 B10 | Blue Ribbon USA | A14 B10 | Blue Ribbon USA | A15 (6 rows)

The END!!!!! Thank you for watching Any Questions?