14
1 MySQL Assignment April 2016 Lecturer: P. De Burca Assignment Game Rental Shop By David Bourke Part 1 E.R Diagram The Main Entities Operational Masters Customers Customer Id Staff Staff Id Suppliers Game Name Shop Stock Game Code Rent Receipt Rent No Over Due Rent No

Mysqldbrentalgamesdb

Embed Size (px)

Citation preview

1

MySQL Assignment April 2016

Lecturer: P. De Burca

Assignment Game Rental Shop

By David Bourke

Part 1

E.R Diagram

The Main Entities Operational Masters

Customers Customer Id

Staff Staff Id

Suppliers Game Name

Shop Stock Game Code

Rent Receipt Rent No

Over Due Rent No

2

Normalisation

UNF 1 NF 2 NF 3 NF

Store Id Store Id PK Store Id PK Store Id PK

Store Address Store Address Store Address Store Address

Customer id Title id Title id Title id

Customer name Title name Title name

Customer address Platform Platform

Title id Cost per game Cost per game

Title name

Platform Store Id PK Store Id PK Store Id PK

Cost per game Customer id PK Customer id Customer id PK

Customer name Customer name Customer name

Customer address

Customer id PK Customer id PK

Customer name Customer name

Customer address Customer address

Title Id

Title id PK

Title name

Platform

Cost per game

3

Part 3 Reports

1 Weekly transactions.

Monday is the first working day of the week.

SELECT * FROM rent_receipt

WHERE date_out BETWEEN ‘2015-04-20 AND 2015—04-26’;

2 Games and their Platform by Publisher Ref shop_stock Table

‘SELECT title, platform,publisher

FROM shop_stock

ORDER BY publisher’;

4

3 list all game which came out in 2015.

Xbox 360 games released in 2015. This is the supplier table. The table named shop_stock

Is the list of games the shop has in stock. The supplier table is a list of xbox games we can

purchase from suppliers.

5

4 List all game with release date 2015 ref shop_stock Table

SELECT title,publisher,release_date

FROM shop_stock

WHERE release_date BETWEEN ‘2015-01-01 AND 2015-12-31’;

6

5 Total all late payments for the month for the month of April 2015

‘SELECT customer _id ,title SUM(total_due) AS grand_total

FROM over_due

WHERE late_return_date BETWEEN ‘2015-04-01’ AND 2015-04-30’

GROUP BY customer_id,title;

6 Total revenues Sum rent_receipt and Sum over_due Tables

SELECT (SELECT SUM(paid) FROM rent_receipt) + (SELECT SUM(total_due) FROM over_due

FROM DUAL;

7

7 Two different methods to list all PS4 games in Stock (not currently out)

SELECT title,platform,in_stock

FROM shop_stock

WHERE in_stock = ‘y’ AND platform = ps4’;

Due to the way I designed the database games are in stock until they are booked out.

Y = yes in stock n = no not in stock. Not sure of a second method.

8

Document and Analysis

Part 4 Testing the database

My original Database was very weak with foreign Keys.

However, I was able to use this database as a dummy database and experiment identifying

issues using Primary key and Foreign Keys’

Another issue I had was how to keep track of games in and games out.

I adopted a very simple column in the Shop Stock Table All games are in Stock ‘Y’

When the game is rented out this table is changed(Updated) to ‘N’

Giving a reading of N (Not in Stock)

Therefor two tables are affected when a customer rents a game.

The rent receipt table is updated and a rent receipt no (Auto increment) is generated

And the Values are inserted.

In the shop stock table, the ‘in_stock column is also updated from ‘y’ to ‘n’

For example, game code 30 is being rented ref table shop stock

When the game is returned the in stock in the shop stock is updated to y

Game being rented out

UPDATE shop_stock SET ‘in_stock’ = ‘n’

WHERE game_id = ‘30’

Game being returned

UPDATE shop_stock SET in_stock = ‘y’

WHERE game id = ‘30’;

It would be unusual for a customer to rent more than one game and even more unusual

For different platforms.

Conclusion: Only one Title is needed in the Rent Receipt Table and Over-Due Tables.

Re The rent_receipt table. The customer books the game and pays for it.

The date out is the booking date and the date return is the expected date return.

If the game is returned after the expected date is it over due.

Then the overdue table is activated, and updated accordingly

To calculate the total of the rent receipts with no late returns

‘SELECT SUM(paid) AS total FROM rent _receipt

Regarding the customers table

I didn’t think it would be necessary to have platform as part of this table

Customers have the choice to change their platforms. If the rental shop sold platforms

Then it would be necessary to keep a record of customer’s platforms. This would lead to a

bigger database or perhaps even another database.

Online resources You tube Derek Banas and www.Stackoverflow

There is one small flaw, I didn’t use any Index, which is faster than a table scan

9

To get the total revenue

Sum of ‘paid’ column from rent receipt table and the sum of ‘total Due’ from overdue table

‘SELECT SUM(paid),(total_due) AS total FROM rent receipt AND overdue’

10

(Test Table)

Other Commands available are concat( adding two column names together) Eg

First name and last name

Inner Join

Selecting a column from different tables and combing them into a report.

11

SELECT rent_no,game_code,first_name,last_name

FROM rent_receipt, customers

WHERE customers.customer_id = rent_receipt.customer_id;

Tables concerned rent_receipt and customers

This is a very powerful way to join different colums from two tables together.

It is also possible to join three tables together.

Design Choice

In total there are six tables.

The customer Table keeps a record of customer_id (Auto Incremented) name , address and phone

Number.

Re table rent receipt. I originally had game code 1, game code 2 and game code 3

In case a customer wanted to rent more than one game a night.However I decided against this

Re Foreign Key issues referencing back to shop_stock game_code and also it would be unusual for a

customer to rent more than one game a night

12

I created a rental table where the game is booked out. This table was seperte to the rent receipt.

The game remains booked out until it is returned.i ended up deleting this table for the simple reason

Of trying to fine tune the database.Minimise data duplication.

The shop_stock table deals with the game_code,(Primary Key) title (FK),cost,publisher,in stock

And release date.

Again trying to minimise data duplication.I could have divided this table into two tables.I thought it

was better to keep as much of game information in the one table.

Supplier table.

Being a small rental shop we some games would be rented out less than others.Therefore

Having every game available in stock is not cost effective.Some games will rent more often than

others.

A report can be ran every week to show what games are being rented out

SELECT game_code,date_out

FROM rent_receipt

WHERE date_out BETWEEN ‘2015-04-20’ AND ‘2015-04-26’

GROUP BY game_code

13

I experimented with another datbase to check multiply fields.

14

I also concidered creating a table per Platform with a more complex code for example

FiFA xbox

The first game has a code of A and the second game (with the same platform) has a code of B)

Platform X Box

Game Name Code

FIFA FXA1

FIFA FXB1

Being a small rental shop a complex code system is not necessary.

A more basic (Auto_INCREMENT) is just as effective.

The staff tableis very straigh forward.

Staff_id is my Primary Key.When a game is rented, There is a field t in the rent_receipt Table to

record which member of staff made the booking.

Loyalty Card

It would have been a bonus to add in a loyalty card per customer.

It was not requested in the assignment and it would have added another Table to the Database.

It might have caused more problems than it was worth,( experience)so in the end I didn’t run with it.