0% found this document useful (0 votes)
82 views11 pages

Game Stop: Scenario

The document describes creating tables for a GameStop database including tables for customers, employees, branch locations, customer records, and game products. It also provides examples of SQL queries using HAVING, DISTINCT, SUM, INNER JOIN, LEFT OUTER JOIN, and CROSS JOIN to query the tables.

Uploaded by

sana fiaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views11 pages

Game Stop: Scenario

The document describes creating tables for a GameStop database including tables for customers, employees, branch locations, customer records, and game products. It also provides examples of SQL queries using HAVING, DISTINCT, SUM, INNER JOIN, LEFT OUTER JOIN, and CROSS JOIN to query the tables.

Uploaded by

sana fiaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Game Stop

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

CREATE TABLE "Customer" (

"ID" INTEGER,

"First Name" TEXT NOT NULL,

"Last Name" TEXT NOT NULL,

"Email" TEXT NOT NULL,

"Address" TEXT,

"Phone Number" NUMERIC,

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)

);

Create Customer Record Table:


CREATE TABLE "Customer_Record" (

"Record_ID" INTEGER,

"Customer_ID" INTEGER NOT NULL,

"Game_ID" INTEGER NOT NULL,

" " INTEGER NOT NULL,

PRIMARY KEY("Record_ID" AUTOINCREMENT),

FOREIGN KEY("Customer_ID") REFERENCES "Customer"("ID"),

FOREIGN KEY("Game_ID") REFERENCES "Game_Product"("Game_ID")

);
Create Game Product Table:
CREATE TABLE "Game_Product" (

"Game_ID" INTEGER,

"Name"TEXT NOT NULL,

"Category" TEXT NOT NULL,

"Description" TEXT,

"Price" INTEGER NOT NULL,

"Stock" INTEGER NOT NULL,

PRIMARY KEY("Game_ID" AUTOCORRECT)

);
Create Supplier Table:
CREATE TABLE "Supplier" (

"Supplier_ID" INTEGER,

"Company_Name" TEXT NOT NULL,

"Email" TEXT NOT NULL,

"Phone Number" NUMERIC NOT NULL,

"Contract_Length" TEXT NOT NULL,

"Company_Address" TEXT NOT NULL,

PRIMARY KEY("Supplier_ID" AUTOINCREMENT)

);
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:

This query shows all distinct emails in employee table

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

LEFT OUTER JOIN:


SELECT * FROM Customer LEFT OUTER JOIN Employee ON Customer.Email=Employee.Email;

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.

You might also like