SlideShare a Scribd company logo
1 of 12
Download to read offline
ASSIGNMENT 1
LOGICAL DATABASE DESIGN (CPT307)
ASADHU SHUJAAU (33475)
FACULTY OF SCIENCE
APRIL 5, 2015
ASSIGNMENT 1 April 5, 2015
P a g e 1 | 11
Table of Contents
Database Design.............................................................................................................................. 2
Entity Relationship Diagram....................................................................................................... 2
Business Rules:........................................................................................................................ 3
Database and Table Creation Queries ......................................................................................... 4
Database Creation.................................................................................................................... 4
Branch Table............................................................................................................................ 4
Shop Table............................................................................................................................... 4
Supplier Table.......................................................................................................................... 4
Sales Table............................................................................................................................... 4
Product Table........................................................................................................................... 5
Stock Table.............................................................................................................................. 5
Products Sold By Shops Table ................................................................................................ 5
Database Results............................................................................................................................. 6
Daily Sales................................................................................................................................... 6
Managing Goods ......................................................................................................................... 8
Good and Amount in Stock......................................................................................................... 9
Number of Items in Stock ......................................................................................................... 10
Cash Received Per Day............................................................................................................. 11
ASSIGNMENT 1 April 5, 2015
P a g e 2 | 11
Database Design
Entity Relationship Diagram
Figure 1: Supermarket ERD
ASSIGNMENT 1 April 5, 2015
P a g e 3 | 11
Supermarket database used in this assignment will consist of 7 tables as shown above. Including a
table for Branch and Shop will help cater for future expansion of the supermarket chain. As shops
increase new shops can be included in the shops table and branch table will help identify where it
operates and which branch controls the shop. Also, the database is created with a table showing
products sold by each shop (ProductSoldByShop). This will help to gain knowledge of the
performance of each shop.
The following are the business rules taken into consideration while creating the database.
Business Rules:
 There are four branches and each shop will fall under any of the four, no other branch.
 Each branch consists of many shops and each shop belongs to one branch.
 Each supplier supplies many products and no two suppliers will supply same product.
 Each shop has its own inventory.
 Many sales can occur in same day hence sale date and a separate table for sale details are
used.
 Same product can be sold by many shops on same day.
Next section will show the database and table creation queries used for this database. The following
queries and other queries has been provided in the CD attached with this document. Queries should
be run in the ascending order with which it have been numbered.
ASSIGNMENT 1 April 5, 2015
P a g e 4 | 11
Database and Table Creation Queries
Database Creation
CREATE DATABASE Supermarket;
Branch Table
CREATE TABLE Branch(
BranchID NVARCHAR(3) NOT NULL PRIMARY KEY,
BranchName NVARCHAR(20) NOT NULL,
BranchStreet NVARCHAR(20) NOT NULL,
BranchCity NVARCHAR(20) NOT NULL,
BranchCountry NVARCHAR(20) NOT NULL
);
Shop Table
CREATE TABLE Shop(
ShopID NVARCHAR(4) NOT NULL PRIMARY KEY,
BranchID NVARCHAR(3) NOT NULL FOREIGN KEY REFERENCES Branch(BranchID)
ON DELETE CASCADE ON UPDATE CASCADE,
ShopName NVARCHAR(20) NOT NULL,
ShopStreet NVARCHAR(20) NOT NULL
);
Supplier Table
CREATE TABLE Supplier(
SupplierID NVARCHAR(4) NOT NULL PRIMARY KEY,
SupplierName NVARCHAR(20) NOT NULL,
SupplierEmail NVARCHAR(50) NOT NULL,
SupplierPhone NVARCHAR(20)
);
Sales Table
CREATE TABLE Sale(
SaleID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
SaleDate DATE NOT NULL,
Revenue MONEY NOT NULL
);
ASSIGNMENT 1 April 5, 2015
P a g e 5 | 11
Product Table
CREATE TABLE Product(
ProductID NVARCHAR(5) NOT NULL PRIMARY KEY,
SupplierID NVARCHAR(4) NOT NULL FOREIGN KEY REFERENCES Supplier(SupplierID)
ON DELETE CASCADE ON UPDATE CASCADE,
ProductName NVARCHAR(20) NOT NULL,
ProductDescription NVARCHAR(50) NOT NULL,
Price MONEY NOT NULL,
ReOrderLevel INT NOT NULL,
ReOrderQty INT NOT NULL
);
Stock Table
CREATE TABLE Stock(
StockID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
ShopID NVARCHAR(4) NOT NULL FOREIGN KEY REFERENCES Shop(ShopID)
ON DELETE CASCADE ON UPDATE CASCADE,
ProductID NVARCHAR(5) NOT NULL FOREIGN KEY REFERENCES Product(ProductID)
ON DELETE CASCADE ON UPDATE CASCADE,
StockLevel INT NOT NULL
);
Products Sold By Shops Table
CREATE TABLE ProductSoldByShop(
PSSID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
ShopID NVARCHAR(4) NOT NULL FOREIGN KEY REFERENCES Shop(ShopID)
ON DELETE CASCADE ON UPDATE CASCADE,
SaleID INT NOT NULL FOREIGN KEY REFERENCES Sale(SaleID)
ON DELETE CASCADE ON UPDATE CASCADE,
ProductID NVARCHAR(5) NOT NULL FOREIGN KEY REFERENCES Product(ProductID)
ON DELETE CASCADE ON UPDATE CASCADE,
QtySold INT NOT NULL
);
ASSIGNMENT 1 April 5, 2015
P a g e 6 | 11
Database Results
Daily Sales
When user inputs sales for each transaction, firstly, the stock gets reduced by the amount sold for
the selected product. Then it calculated total price and enters into the sale table. Following images
show these tasks.
Figure 2: Before Insertion Stock Level
Figure 3: Insertion Query Run Successfully
ASSIGNMENT 1 April 5, 2015
P a g e 7 | 11
Figure 4: StockLevel Reduced After Insertion
Next the total prices are calculated and inserted to Sales tables. Below are the results.
Figure 5: Sale Transaction Table
The above table shows the totals for each sale transaction with the date that transaction took place.
Table below shows from which stock the products were sold from. From this, the related shop can
be found along with the products as Stock table is linked to Shop and Product table.
ASSIGNMENT 1 April 5, 2015
P a g e 8 | 11
Figure 6: Sales Description Showing Totals and Quantity for Each Stock Item
Managing Goods
All the goods or products are managed using Product Table. To help this table additional stock
table is used which identifies the product along with which shop it belongs to. Also, these 2 tables
show stock re-order levels and current stock level for the product. Email setup to send for suppliers
could not be created hence email server cannot be installed into SQL server 2012 express
addition.
Below are screen shots for the tables.
Figure 7: Product Table For Managing Products
ASSIGNMENT 1 April 5, 2015
P a g e 9 | 11
Figure 8: Stock table showing stock for each Shop with Product and Stock Level
Good and Amount in Stock
A join query was used to gain the required output. It is a join between Product and Stock which
shows product description along with its name and stock level.
Queries for this and aforementioned parts and upcoming parts are provided in the CD attached
with this document.
The query output could not fit in this page. So it has been moved to next page.
ASSIGNMENT 1 April 5, 2015
P a g e 10 | 11
Figure 9: SQL INNER JOIN Showing Product and Stock Level
Number of Items in Stock
A simple query was enough to get the number of items in the stock.
Figure 10: Number of Items in Stock
ASSIGNMENT 1 April 5, 2015
P a g e 11 | 11
Cash Received Per Day
A select query was used to generate the total revenue generated on each day. The following table
has been ordered first by day then month then year.
Figure 11: Sale per Day
Other materials related to this Assignment are provided in the CD.

More Related Content

Similar to Logical Database Design for Supermarket Chain

The olap tutorial 2012
The olap tutorial 2012The olap tutorial 2012
The olap tutorial 2012Amin Jalali
 
SQL Server 2008 Portfolio for Saumya Bhatnagar
SQL Server 2008 Portfolio for Saumya BhatnagarSQL Server 2008 Portfolio for Saumya Bhatnagar
SQL Server 2008 Portfolio for Saumya Bhatnagarsammykb
 
Data warehouse project on retail store
Data warehouse project on retail storeData warehouse project on retail store
Data warehouse project on retail storeSiddharth Chaudhary
 
Bierschenk Senior Project
Bierschenk Senior ProjectBierschenk Senior Project
Bierschenk Senior ProjectRyan Bierschenk
 
Sql Server 2008 Portfolio for Vera Vaitsiuk.
Sql Server 2008 Portfolio for Vera Vaitsiuk.Sql Server 2008 Portfolio for Vera Vaitsiuk.
Sql Server 2008 Portfolio for Vera Vaitsiuk.Vera
 
Course Presentation.pdf
Course Presentation.pdfCourse Presentation.pdf
Course Presentation.pdfBiniyamTezera1
 
BDA_S4CLD2208_BPD_EN_US.docx
BDA_S4CLD2208_BPD_EN_US.docxBDA_S4CLD2208_BPD_EN_US.docx
BDA_S4CLD2208_BPD_EN_US.docxTSReddy4
 
MD04 Report in BW
MD04 Report in BWMD04 Report in BW
MD04 Report in BWtasmc
 
Data warehousing
Data warehousingData warehousing
Data warehousingAllen Woods
 
Pivot Tables and Beyond Data Analysis in Excel 2013 - Course Technology Compu...
Pivot Tables and Beyond Data Analysis in Excel 2013 - Course Technology Compu...Pivot Tables and Beyond Data Analysis in Excel 2013 - Course Technology Compu...
Pivot Tables and Beyond Data Analysis in Excel 2013 - Course Technology Compu...Cengage Learning
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolioeileensauer
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolioeileensauer
 
Jessica Herndon Sql Portfolio
Jessica Herndon Sql PortfolioJessica Herndon Sql Portfolio
Jessica Herndon Sql PortfolioJessicaLHerndon
 
Intro to Data warehousing lecture 15
Intro to Data warehousing   lecture 15Intro to Data warehousing   lecture 15
Intro to Data warehousing lecture 15AnwarrChaudary
 

Similar to Logical Database Design for Supermarket Chain (20)

Iowa liquor sales
Iowa liquor salesIowa liquor sales
Iowa liquor sales
 
It ready dw_day4_rev00
It ready dw_day4_rev00It ready dw_day4_rev00
It ready dw_day4_rev00
 
Data warehousing
Data warehousingData warehousing
Data warehousing
 
The olap tutorial 2012
The olap tutorial 2012The olap tutorial 2012
The olap tutorial 2012
 
SQL Server 2008 Portfolio for Saumya Bhatnagar
SQL Server 2008 Portfolio for Saumya BhatnagarSQL Server 2008 Portfolio for Saumya Bhatnagar
SQL Server 2008 Portfolio for Saumya Bhatnagar
 
Data warehouse project on retail store
Data warehouse project on retail storeData warehouse project on retail store
Data warehouse project on retail store
 
Bierschenk Senior Project
Bierschenk Senior ProjectBierschenk Senior Project
Bierschenk Senior Project
 
ggg
 ggg ggg
ggg
 
Sql Server 2008 Portfolio for Vera Vaitsiuk.
Sql Server 2008 Portfolio for Vera Vaitsiuk.Sql Server 2008 Portfolio for Vera Vaitsiuk.
Sql Server 2008 Portfolio for Vera Vaitsiuk.
 
Course Presentation.pdf
Course Presentation.pdfCourse Presentation.pdf
Course Presentation.pdf
 
BDA_S4CLD2208_BPD_EN_US.docx
BDA_S4CLD2208_BPD_EN_US.docxBDA_S4CLD2208_BPD_EN_US.docx
BDA_S4CLD2208_BPD_EN_US.docx
 
MD04 Report in BW
MD04 Report in BWMD04 Report in BW
MD04 Report in BW
 
Query
QueryQuery
Query
 
Data warehousing
Data warehousingData warehousing
Data warehousing
 
Pivot Tables and Beyond Data Analysis in Excel 2013 - Course Technology Compu...
Pivot Tables and Beyond Data Analysis in Excel 2013 - Course Technology Compu...Pivot Tables and Beyond Data Analysis in Excel 2013 - Course Technology Compu...
Pivot Tables and Beyond Data Analysis in Excel 2013 - Course Technology Compu...
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
Jessica Herndon Sql Portfolio
Jessica Herndon Sql PortfolioJessica Herndon Sql Portfolio
Jessica Herndon Sql Portfolio
 
Intro to Data warehousing lecture 15
Intro to Data warehousing   lecture 15Intro to Data warehousing   lecture 15
Intro to Data warehousing lecture 15
 
Creating modeled views
Creating modeled viewsCreating modeled views
Creating modeled views
 

More from Gina Rizzo

How To Write An Empathy Essay By Jones Jessica - I
How To Write An Empathy Essay By Jones Jessica - IHow To Write An Empathy Essay By Jones Jessica - I
How To Write An Empathy Essay By Jones Jessica - IGina Rizzo
 
Rocket Outer Space Lined Paper Lined Paper, Writin
Rocket Outer Space Lined Paper Lined Paper, WritinRocket Outer Space Lined Paper Lined Paper, Writin
Rocket Outer Space Lined Paper Lined Paper, WritinGina Rizzo
 
College Research Paper Writing S
College Research Paper Writing SCollege Research Paper Writing S
College Research Paper Writing SGina Rizzo
 
Research Paper Executive Summary How To Write
Research Paper Executive Summary How To WriteResearch Paper Executive Summary How To Write
Research Paper Executive Summary How To WriteGina Rizzo
 
Hypothesis Experiment 4
Hypothesis Experiment 4Hypothesis Experiment 4
Hypothesis Experiment 4Gina Rizzo
 
Descriptive Essay Introduction Sa
Descriptive Essay Introduction SaDescriptive Essay Introduction Sa
Descriptive Essay Introduction SaGina Rizzo
 
Writing A Personal Letter - MakeMyAssignments Blog
Writing A Personal Letter - MakeMyAssignments BlogWriting A Personal Letter - MakeMyAssignments Blog
Writing A Personal Letter - MakeMyAssignments BlogGina Rizzo
 
How To Write Better Essays Pdf - BooksFree
How To Write Better Essays Pdf - BooksFreeHow To Write Better Essays Pdf - BooksFree
How To Write Better Essays Pdf - BooksFreeGina Rizzo
 
97 In Text Citation Poetry Mla
97 In Text Citation Poetry Mla97 In Text Citation Poetry Mla
97 In Text Citation Poetry MlaGina Rizzo
 
Heart Template - 6 Inch - TimS Printables - Free He
Heart Template - 6 Inch - TimS Printables - Free HeHeart Template - 6 Inch - TimS Printables - Free He
Heart Template - 6 Inch - TimS Printables - Free HeGina Rizzo
 
5 Components Of Fitness Worksheet
5 Components Of Fitness Worksheet5 Components Of Fitness Worksheet
5 Components Of Fitness WorksheetGina Rizzo
 
Cursive Alphabet Zaner Bloser AlphabetWorksheetsFree.Com
Cursive Alphabet Zaner Bloser AlphabetWorksheetsFree.ComCursive Alphabet Zaner Bloser AlphabetWorksheetsFree.Com
Cursive Alphabet Zaner Bloser AlphabetWorksheetsFree.ComGina Rizzo
 
How To Start Your Introduction For A Research Paper. How To Write
How To Start Your Introduction For A Research Paper. How To WriteHow To Start Your Introduction For A Research Paper. How To Write
How To Start Your Introduction For A Research Paper. How To WriteGina Rizzo
 
Custom Admission Essay Dnp A Writing Service Wi
Custom Admission Essay Dnp A Writing Service WiCustom Admission Essay Dnp A Writing Service Wi
Custom Admission Essay Dnp A Writing Service WiGina Rizzo
 
Blank Torn White Paper Template Premium Image
Blank Torn White Paper Template Premium ImageBlank Torn White Paper Template Premium Image
Blank Torn White Paper Template Premium ImageGina Rizzo
 
Green, Yellow, Red The Keys To The Perfect Persua
Green, Yellow, Red The Keys To The Perfect PersuaGreen, Yellow, Red The Keys To The Perfect Persua
Green, Yellow, Red The Keys To The Perfect PersuaGina Rizzo
 
FCE Exam Writing Samples - My Hometown Essay Writi
FCE Exam Writing Samples - My Hometown Essay WritiFCE Exam Writing Samples - My Hometown Essay Writi
FCE Exam Writing Samples - My Hometown Essay WritiGina Rizzo
 
Referencing Essay
Referencing EssayReferencing Essay
Referencing EssayGina Rizzo
 
How To Teach Opinion Writing Tips And Resources Artofit
How To Teach Opinion Writing Tips And Resources ArtofitHow To Teach Opinion Writing Tips And Resources Artofit
How To Teach Opinion Writing Tips And Resources ArtofitGina Rizzo
 
Fantasy Space Writing Paper By Miss Cleve Tea
Fantasy Space Writing Paper By Miss Cleve TeaFantasy Space Writing Paper By Miss Cleve Tea
Fantasy Space Writing Paper By Miss Cleve TeaGina Rizzo
 

More from Gina Rizzo (20)

How To Write An Empathy Essay By Jones Jessica - I
How To Write An Empathy Essay By Jones Jessica - IHow To Write An Empathy Essay By Jones Jessica - I
How To Write An Empathy Essay By Jones Jessica - I
 
Rocket Outer Space Lined Paper Lined Paper, Writin
Rocket Outer Space Lined Paper Lined Paper, WritinRocket Outer Space Lined Paper Lined Paper, Writin
Rocket Outer Space Lined Paper Lined Paper, Writin
 
College Research Paper Writing S
College Research Paper Writing SCollege Research Paper Writing S
College Research Paper Writing S
 
Research Paper Executive Summary How To Write
Research Paper Executive Summary How To WriteResearch Paper Executive Summary How To Write
Research Paper Executive Summary How To Write
 
Hypothesis Experiment 4
Hypothesis Experiment 4Hypothesis Experiment 4
Hypothesis Experiment 4
 
Descriptive Essay Introduction Sa
Descriptive Essay Introduction SaDescriptive Essay Introduction Sa
Descriptive Essay Introduction Sa
 
Writing A Personal Letter - MakeMyAssignments Blog
Writing A Personal Letter - MakeMyAssignments BlogWriting A Personal Letter - MakeMyAssignments Blog
Writing A Personal Letter - MakeMyAssignments Blog
 
How To Write Better Essays Pdf - BooksFree
How To Write Better Essays Pdf - BooksFreeHow To Write Better Essays Pdf - BooksFree
How To Write Better Essays Pdf - BooksFree
 
97 In Text Citation Poetry Mla
97 In Text Citation Poetry Mla97 In Text Citation Poetry Mla
97 In Text Citation Poetry Mla
 
Heart Template - 6 Inch - TimS Printables - Free He
Heart Template - 6 Inch - TimS Printables - Free HeHeart Template - 6 Inch - TimS Printables - Free He
Heart Template - 6 Inch - TimS Printables - Free He
 
5 Components Of Fitness Worksheet
5 Components Of Fitness Worksheet5 Components Of Fitness Worksheet
5 Components Of Fitness Worksheet
 
Cursive Alphabet Zaner Bloser AlphabetWorksheetsFree.Com
Cursive Alphabet Zaner Bloser AlphabetWorksheetsFree.ComCursive Alphabet Zaner Bloser AlphabetWorksheetsFree.Com
Cursive Alphabet Zaner Bloser AlphabetWorksheetsFree.Com
 
How To Start Your Introduction For A Research Paper. How To Write
How To Start Your Introduction For A Research Paper. How To WriteHow To Start Your Introduction For A Research Paper. How To Write
How To Start Your Introduction For A Research Paper. How To Write
 
Custom Admission Essay Dnp A Writing Service Wi
Custom Admission Essay Dnp A Writing Service WiCustom Admission Essay Dnp A Writing Service Wi
Custom Admission Essay Dnp A Writing Service Wi
 
Blank Torn White Paper Template Premium Image
Blank Torn White Paper Template Premium ImageBlank Torn White Paper Template Premium Image
Blank Torn White Paper Template Premium Image
 
Green, Yellow, Red The Keys To The Perfect Persua
Green, Yellow, Red The Keys To The Perfect PersuaGreen, Yellow, Red The Keys To The Perfect Persua
Green, Yellow, Red The Keys To The Perfect Persua
 
FCE Exam Writing Samples - My Hometown Essay Writi
FCE Exam Writing Samples - My Hometown Essay WritiFCE Exam Writing Samples - My Hometown Essay Writi
FCE Exam Writing Samples - My Hometown Essay Writi
 
Referencing Essay
Referencing EssayReferencing Essay
Referencing Essay
 
How To Teach Opinion Writing Tips And Resources Artofit
How To Teach Opinion Writing Tips And Resources ArtofitHow To Teach Opinion Writing Tips And Resources Artofit
How To Teach Opinion Writing Tips And Resources Artofit
 
Fantasy Space Writing Paper By Miss Cleve Tea
Fantasy Space Writing Paper By Miss Cleve TeaFantasy Space Writing Paper By Miss Cleve Tea
Fantasy Space Writing Paper By Miss Cleve Tea
 

Recently uploaded

EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 

Recently uploaded (20)

EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 

Logical Database Design for Supermarket Chain

  • 1. ASSIGNMENT 1 LOGICAL DATABASE DESIGN (CPT307) ASADHU SHUJAAU (33475) FACULTY OF SCIENCE APRIL 5, 2015
  • 2. ASSIGNMENT 1 April 5, 2015 P a g e 1 | 11 Table of Contents Database Design.............................................................................................................................. 2 Entity Relationship Diagram....................................................................................................... 2 Business Rules:........................................................................................................................ 3 Database and Table Creation Queries ......................................................................................... 4 Database Creation.................................................................................................................... 4 Branch Table............................................................................................................................ 4 Shop Table............................................................................................................................... 4 Supplier Table.......................................................................................................................... 4 Sales Table............................................................................................................................... 4 Product Table........................................................................................................................... 5 Stock Table.............................................................................................................................. 5 Products Sold By Shops Table ................................................................................................ 5 Database Results............................................................................................................................. 6 Daily Sales................................................................................................................................... 6 Managing Goods ......................................................................................................................... 8 Good and Amount in Stock......................................................................................................... 9 Number of Items in Stock ......................................................................................................... 10 Cash Received Per Day............................................................................................................. 11
  • 3. ASSIGNMENT 1 April 5, 2015 P a g e 2 | 11 Database Design Entity Relationship Diagram Figure 1: Supermarket ERD
  • 4. ASSIGNMENT 1 April 5, 2015 P a g e 3 | 11 Supermarket database used in this assignment will consist of 7 tables as shown above. Including a table for Branch and Shop will help cater for future expansion of the supermarket chain. As shops increase new shops can be included in the shops table and branch table will help identify where it operates and which branch controls the shop. Also, the database is created with a table showing products sold by each shop (ProductSoldByShop). This will help to gain knowledge of the performance of each shop. The following are the business rules taken into consideration while creating the database. Business Rules:  There are four branches and each shop will fall under any of the four, no other branch.  Each branch consists of many shops and each shop belongs to one branch.  Each supplier supplies many products and no two suppliers will supply same product.  Each shop has its own inventory.  Many sales can occur in same day hence sale date and a separate table for sale details are used.  Same product can be sold by many shops on same day. Next section will show the database and table creation queries used for this database. The following queries and other queries has been provided in the CD attached with this document. Queries should be run in the ascending order with which it have been numbered.
  • 5. ASSIGNMENT 1 April 5, 2015 P a g e 4 | 11 Database and Table Creation Queries Database Creation CREATE DATABASE Supermarket; Branch Table CREATE TABLE Branch( BranchID NVARCHAR(3) NOT NULL PRIMARY KEY, BranchName NVARCHAR(20) NOT NULL, BranchStreet NVARCHAR(20) NOT NULL, BranchCity NVARCHAR(20) NOT NULL, BranchCountry NVARCHAR(20) NOT NULL ); Shop Table CREATE TABLE Shop( ShopID NVARCHAR(4) NOT NULL PRIMARY KEY, BranchID NVARCHAR(3) NOT NULL FOREIGN KEY REFERENCES Branch(BranchID) ON DELETE CASCADE ON UPDATE CASCADE, ShopName NVARCHAR(20) NOT NULL, ShopStreet NVARCHAR(20) NOT NULL ); Supplier Table CREATE TABLE Supplier( SupplierID NVARCHAR(4) NOT NULL PRIMARY KEY, SupplierName NVARCHAR(20) NOT NULL, SupplierEmail NVARCHAR(50) NOT NULL, SupplierPhone NVARCHAR(20) ); Sales Table CREATE TABLE Sale( SaleID INT IDENTITY(1,1) NOT NULL PRIMARY KEY, SaleDate DATE NOT NULL, Revenue MONEY NOT NULL );
  • 6. ASSIGNMENT 1 April 5, 2015 P a g e 5 | 11 Product Table CREATE TABLE Product( ProductID NVARCHAR(5) NOT NULL PRIMARY KEY, SupplierID NVARCHAR(4) NOT NULL FOREIGN KEY REFERENCES Supplier(SupplierID) ON DELETE CASCADE ON UPDATE CASCADE, ProductName NVARCHAR(20) NOT NULL, ProductDescription NVARCHAR(50) NOT NULL, Price MONEY NOT NULL, ReOrderLevel INT NOT NULL, ReOrderQty INT NOT NULL ); Stock Table CREATE TABLE Stock( StockID INT IDENTITY(1,1) NOT NULL PRIMARY KEY, ShopID NVARCHAR(4) NOT NULL FOREIGN KEY REFERENCES Shop(ShopID) ON DELETE CASCADE ON UPDATE CASCADE, ProductID NVARCHAR(5) NOT NULL FOREIGN KEY REFERENCES Product(ProductID) ON DELETE CASCADE ON UPDATE CASCADE, StockLevel INT NOT NULL ); Products Sold By Shops Table CREATE TABLE ProductSoldByShop( PSSID INT IDENTITY(1,1) NOT NULL PRIMARY KEY, ShopID NVARCHAR(4) NOT NULL FOREIGN KEY REFERENCES Shop(ShopID) ON DELETE CASCADE ON UPDATE CASCADE, SaleID INT NOT NULL FOREIGN KEY REFERENCES Sale(SaleID) ON DELETE CASCADE ON UPDATE CASCADE, ProductID NVARCHAR(5) NOT NULL FOREIGN KEY REFERENCES Product(ProductID) ON DELETE CASCADE ON UPDATE CASCADE, QtySold INT NOT NULL );
  • 7. ASSIGNMENT 1 April 5, 2015 P a g e 6 | 11 Database Results Daily Sales When user inputs sales for each transaction, firstly, the stock gets reduced by the amount sold for the selected product. Then it calculated total price and enters into the sale table. Following images show these tasks. Figure 2: Before Insertion Stock Level Figure 3: Insertion Query Run Successfully
  • 8. ASSIGNMENT 1 April 5, 2015 P a g e 7 | 11 Figure 4: StockLevel Reduced After Insertion Next the total prices are calculated and inserted to Sales tables. Below are the results. Figure 5: Sale Transaction Table The above table shows the totals for each sale transaction with the date that transaction took place. Table below shows from which stock the products were sold from. From this, the related shop can be found along with the products as Stock table is linked to Shop and Product table.
  • 9. ASSIGNMENT 1 April 5, 2015 P a g e 8 | 11 Figure 6: Sales Description Showing Totals and Quantity for Each Stock Item Managing Goods All the goods or products are managed using Product Table. To help this table additional stock table is used which identifies the product along with which shop it belongs to. Also, these 2 tables show stock re-order levels and current stock level for the product. Email setup to send for suppliers could not be created hence email server cannot be installed into SQL server 2012 express addition. Below are screen shots for the tables. Figure 7: Product Table For Managing Products
  • 10. ASSIGNMENT 1 April 5, 2015 P a g e 9 | 11 Figure 8: Stock table showing stock for each Shop with Product and Stock Level Good and Amount in Stock A join query was used to gain the required output. It is a join between Product and Stock which shows product description along with its name and stock level. Queries for this and aforementioned parts and upcoming parts are provided in the CD attached with this document. The query output could not fit in this page. So it has been moved to next page.
  • 11. ASSIGNMENT 1 April 5, 2015 P a g e 10 | 11 Figure 9: SQL INNER JOIN Showing Product and Stock Level Number of Items in Stock A simple query was enough to get the number of items in the stock. Figure 10: Number of Items in Stock
  • 12. ASSIGNMENT 1 April 5, 2015 P a g e 11 | 11 Cash Received Per Day A select query was used to generate the total revenue generated on each day. The following table has been ordered first by day then month then year. Figure 11: Sale per Day Other materials related to this Assignment are provided in the CD.