Beruflich Dokumente
Kultur Dokumente
Project
DIT IT211 SQL-Structured Query Language [The database of supermarket]
Name: Wu Jian Min Student ID: 150100000698 Class: IT211-Structured Query Language Country: Brunei Lecturer Name: Mrs. Vangie Wenceslao
IT211
Page 1
Contents
1. Proposal
Page
1.1 Introduction ...................................................................................................................3 1.2 Problem background.....................................................................................................5 1.3 Proposed system............................................................................................................6 1.4 Objective........................................................................................................................9 2. Database description ................................................................................................10 3. Table Description.........................................................................................................11 4. SQL Command Listing 4.1 Restriction and Projection............................................................................................21 4.2 Arithmetic Expression & Operators.............................................................................22 4.3 Null value handling......................................................................................................23 4.4 Aliases..........................................................................................................................23 4.5 Concatenation............................................................................................................23 4.6 Comparison Operator...................................................................................................24 4.7 Logical Operator..........................................................................................................25 4.8 Sorting..........................................................................................................................26 4.9 Function (Group function & Single Row Function)....................................................27 5.0 Use types of joins ........................................................................................................28 5.1 Subqueries....................................................................................................................29 5. Program Testing 5.1 Test Plan.......................................................................................................................30
IT211 Page 2
IT211
Page 3
1. Proposal
Introduction (Background)
Sim Kim Huat supermarket was found in 1970. It is a large supermarket that sells various kinds of goods, such as food, daily products, groceries, toys and so on. Sim Kim Huat currently has a good management. The person who is in charge of the supermarket has created several ideas to control the system of the supermarket. The system of the supermarket can be described as using 6 managements. Those managements are sections, employees, products, stock, sale and customers. The current system of Sim Kim Huat is using paper work to manage the management. (1) Sections The products have been divided into different categories and have been kept in different locations. For example, the location of Daily Products is kept in the location named C1, the location of Home Appliance is kept in another location named C2 and the location of the Furniture is kept in C3. Therefore, customers can find products easily.
(2) Employees: When a person wants to work in Sim Kim Huat supermarket, the applicant will fill in an application form about his or her personal information. The employee information will be kept in a file for future reference. (3) Products The product information, such as model, brand, description, has to be recorded in a product book for future reference. Therefore, employees can order the product that is out of stock from the product information.
IT211
Page 4
(4) Stock If the product is out of stock products, it is ordered from suppliers. Usually, an ordering invoice will be issued and send to the suppliers to place new order products. The ordering invoice contains products arrival date, quantity of the products and the name of the supplier. (5) Sales When a customer buys some products, an employee needs to write the name of the customer, the name of the employee serving the customer, the model and the quantity of the selling products in a receipt. (6) Customer The customer information will be recorded in a customer record book for future reference.
IT211
Page 5
Problem background
The current system of Sim Kim Huat has some problems since Sim Kim Huat has been using paper to record information. Problems are as follows: Sections Sometimes, employees have a hard time to categorise some products. The products will be displayed in the wrong location. Employees Retrieving information of an employee from the employee information may take a long time to find. Products The quantity of every product in the supermarket will be checked weekly. Sometimes, the quantity of the products will be counted wrongly. Stock The handwriting ordering form has created many problems. Firstly, it is hard to read somebody handwriting. Secondly, some products will be forgotten to place order. Sale The information and quantity of sold products will be recorded by employees. However, they will forget to record some sold products when they are busy. Customer The information of a customer will be hard to retrieve from the customer information.
IT211
Page 6
Proposed system
In order to improve the current system and to solve those problems, Sim Kim Huat is planning to use new system. The manager of Sim Kim Huat is going to use databases to store all the information. He is going to break down the information into several tables using Microsoft Access. 1. Sections:
SectionsID S1 S2 Description Daily Product Home Appliance Products Shampoo, comb, perfume Refrigerator, washing machine S3 Furniture Sofa, table
IT211
Page 7
2. Employees
EmployeesID FullName Gender Date of birth E1 John M
01/01/1988
Hire Date
Sections ID
Supervisor ID
20/01/1990
S1
E2 E3
Mary Maggie
F M
02/03/1981 21/09/1983
Kiulap Gadong
8299804 8789065
02/02/1989 31/07/1990
S2 S3
E1 E1
3. Products
ProductID P1 P2 P3 Description Shampoo Refrigerator Table & Chair Model A123 B123 C123 Brand Sun Ligo Court Price $9.90 $990 $290 Made Thailand USA Brunei BarCode 123456789 231231231 123565489 SectionsID S1 S2 S3 Qty at hand 50 10 10
4. Stock:
StockID St1 St2 St3 Supplier Thailand USA Brunei ArrivalDate 30/12/2010 30/12/2010 30/12/2010 ProductID P1 P2 P3 Qty 5 5 5
5. Sale:
IT211
Page 8
SellingDate
EmployeesID
CustomerID
ProductID
Qty
TotalPrice
Warranty
E1 E2 E3
1 2 3
P1 P2 P3
1 2 1
6. Customer
CustomerID 1 2 3 CustomerName Phyllis Rose Hafiz Gender F F M Address Tutong Muara Seria Age 20 30 36
IT211
Page 9
Objective
The objective of the proposed system is to make the daily transaction of the products faster and easy. The system will be greatly help to trace the information of employees, customers, products and sales. The SQL can be performed to do the calculation of the daily transactions by communicating with a database. For example, the total quantity of a product in the supermarket can be known easily with just a click. Overall, the company can reduce a lot of paperworks, and save a lot of time and human energy.
IT211
Page 10
2. Database description
The employees of Sim Kim Huat supermarket are able to gain access to use the database easily by this interface or method. They are able to retrieve the information of each product through the database. This database system is very powerful to keep the information of every linking table by using the primary key of each table. Therefore, the new proposed database can save a lot of memory and the storage in hard disk.
IT211
Page 11
3. Table Description
1. Sections: This table is used to locate the products.
Columns purpose: Columns name SectionsID Description Products Its purpose To record new items in sequential number. To describe the categories of products. To describe products.
Columns data type, width of the column and attribute: Columns name SectionsID Description Products Text Text Text 15 255 255 Yes No No No No No Not Allowed Not Allowed Not Allowed Data type Field size Primary key Foreign key Null
2. Employees It is used to keep the information of every employee. The POS of each employee will be collected to show the selling products of each employee.
IT211
Page 12
Columns purpose: Columns name EmployeesID Purpose To record new employees in sequential number. FullName Gender Date Of Birth Home Address Phone Number To record the names of the employees. To identify the genders of the employees To record the date of birth of the employees To record the address of the employees To record the phones numbers of the employees them easily Date Started To record the beginning date of hiring of every employee. Sections ID Employees are assigned to manage the categories of products. SupervisorID To record supervisor in sequential number.
Columns data type, width of the column and attribute: Columns name EmployeesID FullName Gender
IT211
Data type
Field size
Primary key
Foreign key
Null
20 255 10
Yes No No
No No No
Date Of Birth Home Address Phone Number Date Started Sections ID SupervisorID
Date/Time Text
8 bytes 255
No No
No No
Text
255
No
No
Allowed
8 bytes 15 15
No No No
No Yes No
IT211
Page 14
Columns purpose Columns name ProductID Description Purpose To record new items in sequential number. To record the description of the new products. Model Brand Price To record the models of the new products. To record the brands of the new products. To record the regular prices of the new products Made To record the products are made from which countries. Barcode SectionsID Qty at hand To record the barcode of each products. To categorize new products. To record the number of rest products
IT211
Page 15
Columns data type, width of the column and attribute: Columns name ProductID Description Model Brand Price Made Barcode SectionsID Qty at hand Text Text Text Text Currency Text Text Text Number 15 255 100 100 8 bytes 100 20 15 8 bytes Yes No No No No No No No No No No No No No No No Yes No Not allowed Not allowed Not Allowed Not Allowed Not Allowed Not Allowed Not Allowed Not Allowed Not Allowed Data type Field size Primary key Foreign key Null
IT211
Page 16
Columns purpose Columns name StockID Supplier ArrivalDate ProductID Purpose To record new orders in sequential number. To record supplier New product arriving date To record the sales of the products. To match information of Products Qty The numbers of new products
Columns data type, width of the column and attribute: Columns name StockID Supplier ArrivalDate ProductID Qty Text Text Date/Time Text Number 15 15 8 bytes 15 8 bytes Yes No No No No No No No Yes No Not allowed Not Allowed Not Allowed Not Allowed Not Allowed Data type Field size Primary key Foreign key Null
5. Sale The table is used to record what products have been sold and how many have been sold.
IT211 Page 17
Columns purpose: Columns name InvoiceNumber Sellingdate EmployeesID Purpose To record the sales of the receipts in sequential number To record the date of the sold product To record the ID of the staff. The purpose is used to identify the sold products are sold by which employees. To record which customer purchase the product To record the sales of the products. The quantitis of the sold products. The amount of the sold products. To record how many years warranty the product has.
IT211
Page 18
Columns data type, width of the column and attribute: Columns name InvoiceNumber Text SellingDate EmployeesID CustomerID ProductID Qty TotalPrice Warranty Date/Time Text Text Text Number Currency Text 15 8 bytes 15 255 15 8 bytes 8 bytes 15 Yes No No No No No No No No No Yes Yes Yes No No No Not Allowed Not Allowed Not Allowed Not Allowed Not Allowed Not Allowed Not Allowed Allowed Data type Field size Primary key Foreign key Null
IT211
Page 19
6. Customer This table is used to record customers information in case customer wants to change product that purchase from here. The manager can check this table to confirm it is true. This table is link to sale table.
Columns purpose Columns name CustomerID CustomerName Gender Address Age Purpose To record the customer has been purchased products from here in sequential number To record customers name To record gender of each customer. To record customers address To record customers age
IT211
Page 20
Columns data type, width of the column and attribute: Columns name CustomerID Auto Number CustomerName Text Gender Address Age Text Text Number 15 15 255 15 No No No No No No No No Not Allowed Not Allowed Not Allowed Not Allowed 255 Yes No Not Allowed Data type Field size Primary key Foreign key Null
IT211
Page 21
Output:
Output:
IT211
Page 22
4.2 Arithmetic Expression & Operators (3) Arithmetic Expression: Total stock
Output:
Total sold
Output:
Total balance
Output:
IT211
Page 23
4.3 Null value handling (4) Using NZ function to retrieve data from Sale:
Output:
Output:
Output:
IT211
Page 24
Output:
Output:
IT211
Page 25
4.7 Logical Operator (9) Using Sale table to do Logical Operator by using And function:
Output:
Output:
IT211
Page 26
4.8 Sorting (11) Using Sorting function to descend the price of products:
Output:
Output:
IT211
Page 27
4.9 Function (Single Row Function & Group function) (13) Using Case Conversion function under Customer table:
Output:
Output:
IT211
Page 28
Output:
5.0 Use types of joins (16) Using Equijoin function under Sections table and Employees table:
Output:
IT211
Page 29
Output:
5.1 Subqueries (18) Using subquery function to display who has the same supervisor as Jasmine under employees table
Output:
IT211
Page 30
5. Program Testing
5.1 Test Plan
Objective To display SectionsID that it is S1 and S3, Description, Products that we want from Sections table To retrieve four columns those are EmployeesID, FullName, HomeAddress, SectionsID from Employees table To calculate remaining quantity of products and display ProductID, QtyAtHand, TotalStock, TotalSold and QtyAtHand.
(2) (3)
(4) (5) (6) (7) (8) (9) (10) (11) (12) (13) (14) (15) (16)
IT211
To use None Warranty to represent Null value in Warranty column under Sale table To Aliases Arrival Date as New Arrival Date after arrival date delaying 30 days Using concatenation function to form sentence to introduce products information under products table To retrieve employees who was born before 4/4/1973 To retrieve employees who did not have phone To display products which they was selling out two before 2/1/2011 from sale table To display products which they are in S1 and S3 or they belongs to vegetable from sections table To descend the price of products from Products table To ascend the price of products from Products table To change CustomerName into Capital letter and change Address into Lower case letter from customer table To format date into another type from stock table To count how many employees in employees table To combine Sections and Employees table into one table.
Page 31
(17) (18)
To find each employees their supervisor name To find who has the same supervisor as Jamine
IT211
Page 32
5.2 Test Cases and Results Test Case: (1) Objective: To display SectionsID that it is S1 and S3, Description, Products that we want from Sections table. Test Data:
Statement:
Expected Test Result: The output result will displayed S1 and S2 rows.
Conclusion: Test successful Test Case: (2) Objective: To retrieve four columns those are EmployeesID, FullName, HomeAddress, SectionsID from Employees table. Test Data:
IT211
Page 33
Statement
Expected Test Result: Only EmployeesID, FullName, HomeAddress, SectionsID columns will display.
Conclusion: Test successful Test Case: (3) Objective: To calculate remaining quantity of products and display ProductID, QtyAtHand, TotalStock, TotalSold and QtyAtHand. Test Data:
IT211 Page 34
Statement
Expected Test Result: ProductID, QtyAtHand, TotalStock, TotalSold and QtyAtHand columns will display on one table. Actual Test Result:
Test Case: (4) Objective: To use None Warranty to represent Null value in Warranty column under Sale table
IT211
Page 35
Test Data:
Statement
Expected Test Result: InvoiceNumber, Sellingdate, ProductID, warranty and New Warranty which changes Null value into None warranty will be displayed on one table.
IT211
Page 36
Test Case: (5) Objective: To Aliases Arrival Date as New Arrival Date after arrival date delaying 30 days table
Test Data:
Statement
Expected Test Result: StockID, Supplier, ArrivalDate and New Arrival Date which date is delayed 30 days will be displayed on one table.
Test Case: (6) Objective: Using concatenation function to form sentence to introduce products information under products table
Test Data:
IT211 Page 37
Statement
Expected Test Result: We use two sentences to describe the products detail in one table.
Test Case: (7) Objective: To retrieve employees who were born before 4/4/1973
Test Data:
Statement
IT211
Page 38
Expected Test Result: The information of employees who were born before 4/4/1973 will be displayed.
Test Case: (8) Objective: To retrieve employees who did not have phone number
Test Data:
Statement
The information of employees who did not have phone number will be displayed.
Test Case: (9) Objective: To display products which they were selling out two before 2/1/2011 from sale table
Test Data:
Statement:
Expected Test Result: The information of products which were selling out before 2/1/2011 will be displayed. Actual Test Result:
IT211
Page 41
Test Case: (10) Objective: To display products which they are in S1 and S3 or they belongs to vegetable from sections table Test Data:
Statement
Expected Test Result: The information of products which located S1 and S2 and vegetable products will be displayed. Actual Test Result:
Test Case: (11) Objective: To descend the price of products from Products table
Test Data:
IT211
Page 42
Statement:
Expected Test Result: The price of products will arrange from higher to lower.
IT211
Page 43
Test Case: (12) Objective: To ascend the price of products from Products table
Test Data:
Statement:
Expected Test Result: The price of products will arrange from lower to higher.
Test Case: (13) Objective: To change CustomerName into Capital letter and change Address into Lower case letter from customer table
Test Data:
Statement:
Expected Test Result: The customer name will displayed by using capital letter and address will displayed by using lower case letter. Actual Test Result:
Test Case: (14) Objective: To format date into another type from stock table Test Data:
IT211
Page 45
Statement:
Expected Test Result: The Arrival Date will be formatted by another form, such as dd-mmm-yyyy.
IT211
Page 46
Test Case: (15) Objective: To count how many employees in employees table Test Data:
Statement
Expected Test Result: The new table will count number of people in each
Test Case: (16) Objective: To combine Sections and Employees table into one table. Test Data:
IT211
Page 47
IT211
Page 48
Statement
Expected Test Result: The new table will display FullName, DateStarted, Description, SectionsID that are from Employees and Sections table.
Test Case: (17) Objective: To find each employees their supervisor name Test Data:
IT211
Page 49
Statement
Expected Test Result: The new table will display the information of employees under which supervisor.
IT211
Page 50
Test Case: (18) Objective: To find who has the same supervisor as Jamine. Test Data:
Statement:
Expected Test Result: The new table will display the information of employees FullName and supervisorID
IT211
Page 51
IT211
Page 52
6. User Manual
Program Installation: 1. Microsoft Access 2007 must be required to install on the computer. 2. Copy supermarket file from Installation CD to any drive or desktop. 3. Double left click supermarket.accdb file to run the program. To run each table steps: 1. All Tables displayed on the left pattern after running the supermarket program.
2. Select any table that user wants. Then just double left click to open the table. For example: Sections table.
IT211
Page 53
3. If users want to open query that it already retrieve some information using query. To find icon on the left pattern and double left click to open. For example: Equijoin.
4. If users want to retrieve some information from one table. Click Create under menu bar and click Query Design. Or users want to create new table, then click table after clicking Click Create under menu bar.
IT211
Page 54
7. Conclusion/ Comment
I have absorbed a lot of knowledge from my lecturer who has taught us <Structured Query Language> in details. We practiced SQL exercises after each chapter by using Microsoft Access. SQL is used to communicate with a database. Under Microsoft Access software, there are many functions. Now I know how to write basic SQL statements, restrict and sort data, use single-row functions, use multiple-row functions, implement joining tables and write subqueries. And I also know how to define parameters query in Access. SQL is powerful and easy to use. Access can store many data and retrieve data easily that it is simple to write statement using SQL.
IT211
Page 55