Game Stop: Scenario
Game Stop: Scenario
Contents
Scenario:.....................................................................................................................................................1
Create Database..........................................................................................................................................1
Create Tables:.............................................................................................................................................2
Create Customer Table:..........................................................................................................................2
Create Employee Table:..........................................................................................................................3
Create Branch Location Table:................................................................................................................4
Create Customer Record Table:..............................................................................................................5
Create Game Product Table:...................................................................................................................6
Create Supplier Table:.............................................................................................................................7
Queries:.......................................................................................................................................................8
Having:....................................................................................................................................................8
Distinct:...................................................................................................................................................9
Sum:........................................................................................................................................................9
INNER JOIN:...........................................................................................................................................10
LEFT OUTER JOIN:.................................................................................................................................10
CROSS JOIN:..........................................................................................................................................11
Summary:..................................................................................................................................................11
Scenario:
A game shop named GameStop contains many branches. These branches have a manager for
every branch and different salesmen. These branches sells games of different categories and each
category have different games. These games are provided by different suppliers and each supplier can
provide different categories of games, similarly same game can be provided by different suppliers.
Customer can visit any branch and buy any game by speaking to employee. A customer can buy many
games but a game can be bought by one customer only. The record of customer shopping is kept in
customer record which contains information about customer and game.
Create Database
Create Database GameStop
Create Tables:
Create Customer Table:
Use GameStop
"ID" INTEGER,
"Address" TEXT,
PRIMARY KEY("ID")
);
Create Employee Table:
Use GameStop
CREATE TABLE Employee (
"Employee_ID" INTEGER,
"First Name" TEXT NOT NULL,
"Last Name" TEXT NOT NULL,
"Email" TEXT NOT NULL,
"Job Title" TEXT NOT NULL,
"Salary" INTEGER NOT NULL,
"Hired Date" TEXT NOT NULL,
PRIMARY KEY("Employee_ID " AUTOINCREMENT)
);
Create Branch Location Table:
use GameStop
CREATE TABLE "Branch_Location" (
"Location_ID" INTEGER ,
"Street" TEXT NOT NULL,
"City" TEXT NOT NULL,
"Province" TEXT NOT NULL,
"Country" TEXT NOT NULL,
"ZipCode" INTEGER NOT NULL,
PRIMARY KEY("Location_ID" AUTOINCREMENT)
);
"Record_ID" INTEGER,
);
Create Game Product Table:
CREATE TABLE "Game_Product" (
"Game_ID" INTEGER,
"Description" TEXT,
);
Create Supplier Table:
CREATE TABLE "Supplier" (
"Supplier_ID" INTEGER,
);
Queries:
Having:
SELECT * FROM Employee GROUP By Salary HAVING Salary>1000
Description:
This query shows all record having salary greater than 1000
Distinct:
SELECT DISTINCT Email FROM Employee
Description:
Sum:
SELECT sum(Salary) FROM Employee GROUP BY Salary
Description:
This query shows the sum of salary of employee having same salary
INNER JOIN:
SELECT * FROM Customer INNER JOIN Employee ON Customer.ID=Employee.Employee_ID;
Description:
This query show all record in table Customer and Employee where IDs are same
Description:
This query show all record in table Customer and records with matching emails from
table Employee
CROSS JOIN:
SELECT * FROM Customer CROSS JOIN Employee;
Description:
This query results in Cartesian product of table Customer and Table Employee.
Summary:
I did not encounter any problem except for “foreign key constraint failed” in customer record
table which I later found out was due to mismatching id in customer and employee table.