SQL Database for a Book Store Clinton McKay. Explanation The database contains information about the books held in stock, their authors, publishers, customers,

Slides:



Advertisements
Similar presentations
SQL – Lesson II Grade 12.
Advertisements

Sorting Rows. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Construct a query to sort a results set in ascending.
Information Systems Today: Managing in the Digital World
BACS 485 Structured Query Language 2. BACS 485 SQL Practice Problems Assume that a database named COLLEGE exists. It contains the tables defined below.
Draw an ER Diagram for the following (record any assumptions):
 To provide you with an overview of the aspects that make up a relational database.  This includes: › Tables › Records › Fields › Data types › Keys.
Table design screen Field name Data type Field size Other properties.
Access - 1 Table Query (View) FormReport Database Application Basic Database Objects Relationships among Access Database Objects A saved SELECT query is.
1 The Information School of the University of Washington Nov 29fit forms © 2006 University of Washington More Forms INFO/CSE 100, Fall 2006 Fluency.
Data modelling uses two main techniques Entity relationship (E-R) modelling: a top- down approach Normalisation: a bottom-up approach.
1 LBSC 690: Week 9 SQL, Web Forms. 2 Discussion Points Websites that are really databases Deep vs. Surface Web.
Database – Part 2a Dr. V.T. Raja Oregon State University.
Interpreting SQL Code. SQL (The language used to query a database) S is used to specify the you want to include. F is used to specify the the selected.
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?
Creating a Database in Access Creating a database involves 1.Logical design of tables and relationships 2.Physical design of tables and relationships 3.Populating.
Case study Lisa’s Bookstore IST210.
CORE 2: Information systems and Databases STORAGE & RETRIEVAL 2 : SEARCHING, SELECTING & SORTING.
Computer Science 101 Web Access to Databases SQL – Extended Form.
Database Relationships Objective 5.01 Understand database tables used in business.
2.3 Organising Data for Effective Retrieval
Xin  Syntax ◦ SELECT field1 AS title1, field2 AS title2,... ◦ FROM table1, table2 ◦ WHERE conditions  Make a query that returns all records.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
School of Business Administration
CSE 441: Systems Analysis & Design
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,
DESIGNED BY AMIT KUMAR DUTTA( ) FAHIAN AHMED( )
The 2 nd Hand Student Book Database Jon Havier High Distinction Assignment, Autumn 2007.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
Information Systems: Databases Define the role of general information systems Describe the elements of a database management system (DBMS) Describe the.
What we’ve learnt Doc 5.69 Doc 5.70 Section 1-3. A simple database Related objects Tables hold the data Forms, reports, queries to access the data.
Customer Order Order Number Date Cust ID Last Name First Name State Amount Tax Rate Product 1 ID Product 1 Description Product 1 Quantity Product 2 ID.
ADO.NET Data Access. Page  2 SQL  When we interact with the datasource through ADO.NET we use the SQL language to retrieve,modify,update information.
CS 1308 Computer Literacy and the Internet
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Game Store Database. To start off, the purpose of this particular database design is to regulate the basic inner workings of a game store. This design.
INFORMATION TECHNOLOGY DATABASE MANAGEMENT. Adding a new field 1Right click the table name and select design view 2Type the field information at the end.
Forms and Subforms 5.02 Understand database queries, forms, and reports used in business.
An Entity Relationship (ER) Diagram is a graphic that shows the interrelationship between entities in a database.
Normalization Exercise. First Normal Form Second Normal Form.
Query Lab CSC 240 Blum1. Log on to PMA (PHPMyAdmin) and click on the Northwind database CSC 240 Blum2.
* 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.
LINQ to DATABASE-2.  Creating the BooksDataContext  The code combines data from the three tables in the Books database and displays the relationships.
Drill Consider the following tables with the following fields: Student: FName, LName, StudentID, Age, Yr, Course Grades: ID, P1, P2, P3 1.Display the.
Database Relationships Objective 5.01 Understand database tables used in business.
Object Oriented Analysis and Design COSC 4250 Project: “Blue Sky Bookstore” Team: Pan Gao and Dennis Gallie October 8, 2007.
Databases Flat Files & Relational Databases. Learning Objectives Describe flat files and databases. Explain the advantages that using a relational database.
Power Designer n See course web page for additional information on using Power Designer n Business rules – Come from a description of activities – Example.
Databases – Part 2 Task 1 – Simple Query and Report Create a Report for the following scenarios. Remember before you create the.
G057 - Lecture 05 From Scenario To Design Mr C Johnston ICT Teacher
DATA MODELING AND ENTITY-RELATIONSHIP MODEL II IST 210: Organization of Data IST210 1.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Database Relationships
Week 03 – ER Diagram INFOSYS 222.
Database Mysql Hayk Avdalyan.
 2012 Pearson Education, Inc. All rights reserved.
Information Systems Today: Managing in the Digital World
Chapter 12 Information Systems.
LINQ to DATABASE-2.
Introduction to Database Systems
INFO/CSE 100, Spring 2005 Fluency in Information Technology
5.02 Understand database queries, forms, and reports used in business.
Entity – Relationship Model
Process Diagram for Sally’s Bookstore (as written)
Bookstore DB Requirements
INFO/CSE 100, Spring 2006 Fluency in Information Technology
Database Relationships
Flat Files & Relational Databases
How to use the library catalogue
Advanced Database Concepts: Reports & Views
Section 4 - Sorting/Functions
Presentation transcript:

SQL Database for a Book Store Clinton McKay

Explanation The database contains information about the books held in stock, their authors, publishers, customers, sales. The database was populated with information from bibliographic records in IUCat (with some modifications) and do not necessarily represent actual publications. The SQL queries I designed are meant to gather different kinds of useful information about the business.

Entity Relationship Diagram

Data Dictionary

Query 1 List all titles in book and include ISBN, author name (as combined from author.fname and author.lname) and the publisher name. SELECT book.title AS "Title", book.isbn AS "ISBN", CONCAT(author.fname, ' ', author.lname) AS "Author", publisher.name AS "Publisher" FROM book, author, publisher WHERE author.author_id=book.author_id AND publisher.publisher_id=book.publis her_id;

Query 2 List all customers who have purchased books published since SELECT customer.fname, customer.lname, book.title, book.publication_date FROM customer JOIN sale ON customer.customer_id=sale.cust_i d JOIN book ON sale.isbn=book.isbn JOIN author ON author.author_id=book.author_id WHERE book.publication_date >= 2007;

Query 3 List customers (as combined from customer.fname and customer.lname) who have purchased books published in the UK or the US, as well as the title of the book they purchased and the name of its publisher and order by last name of customer. SELECT CONCAT(customer.fname, ' ', customer.lname), book.title, publisher.country, publisher.name FROM customer JOIN sale ON customer.customer_id = sale.cust_id JOIN book ON sale.isbn = book.isbn JOIN publisher ON book.publisher_id = publisher.publisher_id WHERE publisher.country ='UK' or publisher.country ='US' ORDER BY customer.lname;

Query 4 List the number of books sold that have been written by each author and group by authors first name, then last name. SELECT COUNT(sale.isbn) AS "Number of books sold", CONCAT(author.fname, ' ', author.lname) AS "Author" FROM sale JOIN book ON sale.isbn = book.isbn RIGHT JOIN author ON book.author_id=author.author_id GROUP BY author.fname, author.lname;

Query 5 List the different (distinct) genres and how many books belong to each genre, order alphabetically by genre. SELECT distinct book.genre, COUNT(book.genre) FROM book GROUP BY book.genre ORDER BY book.genre ASC;

Query 6 List the names and phone numbers of all distinct customers who have ordered books published by US or UK publishers, sort them alphabetically. SELECT DISTINCT (CONCAT (customer.fname, ' ', customer.lname)) AS "Customer Name", customer.phone AS "Customer Phone Number" FROM customer JOIN sale ON sale.cust_id = customer.customer_id JOIN book ON book.isbn = sale.isbn WHERE (CONCAT (customer.fname, ' ', customer.lname)) IN (SELECT CONCAT(customer.fname, ' ', customer.lname) FROM customer JOIN sale ON customer.customer_id = sale.cust_id JOIN book ON sale.isbn = book.isbn JOIN publisher ON book.publisher_id = publisher.publisher_id WHERE publisher.country ='UK' or publisher.country ='US') ORDER BY CONCAT(customer.fname, ' ', customer.lname);

Query 7 List customers first and last names ordered by the number of books they have purchased, ordered by the number of books purchased. SELECT COUNT(sale.cust_id) AS "Number of Books Purchased", CONCAT (customer.fname, ' ', customer.lname) AS "Customer Name" FROM sale JOIN customer ON customer.customer_id = sale.cust_id GROUP BY customer.fname, customer.lname ORDER BY (COUNT(sale.cust_id)) DESC;

Query 8 List the number of records in each table (book, author, sale, customer, and publisher). SELECT DISTINCT (SELECT COUNT(*) FROM book) AS "Books", (SELECT COUNT(*) FROM author) AS "Authors", (SELECT COUNT(*) FROM sale) AS "Sales", (SELECT COUNT(*) FROM customer) AS "Customers", (SELECT COUNT(*) FROM publisher) AS "Publishers" FROM book JOIN author ON author.author_id = book.author_id JOIN sale ON sale.isbn = book.isbn JOIN customer ON customer.customer_id=sale.cust_id JOIN publisher ON publisher.publisher_id = book.publisher_id;

Query 9 Create and display a view of all sales with customer name, title of book, author last name, isbn of book, and publisher name. CREATE VIEW listsales AS SELECT CONCAT(customer.fname, ' ', customer.lname) AS "Customer Name", book.title AS "Book", author.lname AS "Author Last Name", book.isbn AS "ISBN", publisher.name AS "Publisher" FROM customer JOIN sale ON customer.customer_id = sale.cust_id JOIN book ON sale.isbn = book.isbn JOIN author ON author.author_id = book.author_id JOIN publisher ON book.publisher_id = publisher.publisher_id ORDER BY customer.lname; SELECT * FROM listsales;

Query 10 Books are organized by ISBNBooks with ISBNs greater than are housed on the third floor, those with ISBNs between and are housed on the second floor, and all others are on the first floor. List all books with their locations. SELECT book.title AS "Title", CASE WHEN book.isbn >= THEN 'Located on Third Floor' WHEN book.isbn <= THEN 'Located on First Floor' ELSE 'Located on Second Floor' END AS "Location" FROM book;