Tải bản đầy đủ (.docx) (33 trang)

THE PROGRESS EXERCISE FOR DATABASE SUMMARY OF ALL supermarket database system with ERD model and relational model, simple queries

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (2.04 MB, 33 trang )

1

VIETNAM GENERAL CONFEDERATION OF LABOR
TON DUC THANG UNIVERSITY FACULTY OF
INFORMATION TECHNOLOGY

THE PROGRESS EXERCISE FOR DATABASE

SUMMARY OF ALL

Instructors: MR.MAI VĂN MẠNH
Student:

MAI BẢO THẠCH – 520H0490
Class:

20H50304

Course:

HO CHI MINH CITY, 2021

24


2

VIETNAM GENERAL CONFEDERATION OF LABOR
TON DUC THANG UNIVERSITY FACULTY OF
INFORMATION TECHNOLOGY


THE PROGRESS EXERCISE FOR DATABASE

SUMMARY OF ALL

Instructor: MR. MAI VĂN MẠNH
Student: MAI BẢO THẠCH – 520H0490
Class:

20H50304

Course:

HO CHI MINH CITY, 2021

24


3

THANKFUL WORD
After working for a whole semester with the enthusiastic help and support
of Mr. Mai Văn Manh, I was able to complete the report in the most complete and
effective way. His teaching has given our students a lot of knowledge as well as
full skills in the specialized subject. Although couple of months is quite short, but
that time has also helped me to easily approach the major step by step with a solid
foundation, especially with the encouragement and help from seasoned lecturers.
I sincerely thank


4


REPORT COMPLETED AT TON DUC THANG
UNIVERSITY
I hereby declare that this is my own report and is under the guidance of Mr.
Mai Văn Mạnh. The research contents and results in this topic are honest and have
not been published in any form before. The data in the tables for analysis,
comments and evaluation are collected by the author himself from different
sources, clearly stated in the reference section.
In addition, the project also uses a number of comments, assessments as
well as data of other authors, other agencies and organizations, with citations and
source annotations.
If I find any fraud I take full responsibility for the content of my
report. Ton Duc Thang University is not related to copyright and copyright
violations caused by me during the implementation process (if any).
Ho Chi Minh city, 12 May, 2022
Author
(sign and write full name)

Mai Bảo Thạch


5

TEACHER’S CONFIRMATION AND ASSESSMENT
SECTION
Confirmation section of the instructors

________________________________________________
_____________________________________________________
_____________________________________________________

_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_________________________________
Ho Chi Minh city, day month year
(sign and write full name)

The evaluation part of the lecturer marks the report

________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_________________________________
Ho Chi Minh city, day month year
(sign and write full name)


6

SUMMARY
The assignment is built for the purpose of testing database’s knowledge about erd
model and relational model, but also for consolidating knowledge after studying at
school. The content of the assignment revolves around reviewing the basic
knowledge of the logic SQL syntaxes and logic query as well as coding
implementation for connect and using database throughout Java and Python.

Regarding the research method, the assignment is based on the learned knowledge,
lecture slides, and textbooks given by the lecturer during the learning process. The
result obtained after this assignment is the knowledge that can be consolidated in
the most general way as well as in place of the assignment of the 1st term during
the period of extremely stressful epidemic developments.


7

TABLE OF CONTENTS

THANKFUL WORD............................................................................................................................ 3
REPORT COMPLETED AT TON DUC THANG UNIVERSITY....................................... 4
TEACHER’S CONFIRMATION AND ASSESSMENT SECTION.................................... 5
SUMMARY............................................................................................................................................. 6
TABLE OF CONTENTS.................................................................................................................... 7
LIST OF ABBREVIATION............................................................................................................... 7
LIST OF DIAGRAMS, CHARTS AND TABLES...................................................................... 8
CHAPTER 1: WORKING ARRANGEMENT........................................................................... 9
1.1

Introduction of other chapters:.......................................................................... 9

CHAPTER 2: Supermarket database system with ERD model and
Relational model, simple queries.................................................................................................. 10
CHAPTER 3: Using Java to behaving some queries related to SQL and
database with maven project.......................................................................................................... 21
REFERENCES.................................................................................................................................... 31
APPENDIX............................................................................................................................................ 32



8

LIST OF ABBREVIATION


9

LIST OF DIAGRAMS, CHARTS AND TABLES
Picture 1 ERD model............................................................................................................. 14
Picture 2 Relational model................................................................................................... 15
Picture 3 Create database and tables (1)........................................................................... 16
Picture 4 Create database and tables (2)........................................................................... 17
Picture 5 Inserting datas........................................................................................................ 18
Picture 6 Product table.......................................................................................................... 19
Picture 7 Procedure 2............................................................................................................ 19
Picture 8 Invoice table after executing procedure.......................................................... 20
Picture 9 Function 1............................................................................................................... 20
Picture 10 Price of R1 receipt.............................................................................................. 21
Picture 11 R1’s row for comparison................................................................................... 21
Picture 12 Trigger 2............................................................................................................... 21
Picture 13 Result on subtracting on R1’s quantity......................................................... 22
Picture 14 Create database................................................................................................... 24
Picture 15 Define path connection and login information............................................ 24
Picture 16 Result of creating database.............................................................................. 25
Picture 17 Create Employee table...................................................................................... 25
Picture 18 Result in screen................................................................................................... 25
Picture 19 Result in MSSQL............................................................................................... 26
Picture 20 Employee class.................................................................................................... 27
Picture 21 Inserting method................................................................................................. 28

Picture 22 Reading and returning method........................................................................ 29
Picture 23 Reading an employee's information by specified ID method.................29
Picture 24 Updating an employee method........................................................................ 30
Picture 25 Deleting an employee method......................................................................... 30


10

Picture 26 Calling method in main()................................................................................. 31
Picture 27 Result on screem of inserting method........................................................... 31
Picture 28 Result on MSSQL of inserting method......................................................... 31
Picture 29 Result on screem of reading and returning method................................... 32
Picture 30 Result on screem of returning an employee by ID method......................32
Picture 31 Result of updating mehod on screen............................................................. 32
Picture 33 Result of deleting on MSSQL......................................................................... 32
Picture 32 Result of deleting on screen............................................................................ 32
Picture 34 Result of updating mehod on MSSQL.......................................................... 32


11

CHAPTER 1: WORKING ARRANGEMENT
1.1 Introduction of other chapters:
Chapter 2: Supermarket database system with ERD model and Relational model,
simple queries.
Chapter 3: Using Java to behaving some queries related to SQL and database with
maven project.


12


CHAPTER 2: Supermarket database system with
ERD model and Relational model, simple queries
PART 1: (6 POINTS)
Given the following specification:
A supermarket needs to build an item management system. The
supermarket currently has the following activities: Supermarket imports products
from suppliers. The suppliers offer a variety of products in varying quantities.
Each product needs to be stored with product code, product name, unit, quantity,
and price. Each product is made by only one manufacturer. The information of
manufacturer is: manufacturer code, manufacturer name, nationality. When the
products are imported, it is necessary to save the receipt, including information
such as: receipt code, imported products, supplier, quantity, price, import date. The
information about the supplier is the supplier code, full name, address.
Supermarkets have many sales counters, but each product is only sold at
only one counter. Information of counter includes counter number, counter name,
location.
Customers will go to the supermarket to buy products. When a customer
makes a purchase, the system will print out a invoice that includes information
about the invoice code, customer, products, quantity, and price. Customer
information includes customer code, customer name, address.
1. Draw ERD model (1 point)
2. Convert the ERD model to a relational model (1 point)


13

3. Use SQL language to fulfill the following requirements for the above relational

model: (1)

a. Create Database
b. Create table
c. Add at least 10 datarow to each table.
4. Create a procedure for one of the following requirements: (1 point)

a. a. Create a new receipt
b. Add data to the invoice
c. Add data to the product
5. Create a function for one of the following requirements: (1 point)

a. Indicate the total amount for a certain receipt.
b. Indicate the total amount for a certain invoice
6. Create a trigger for one of the following requirements: (1 point)

a. Update the quantity and price for the product when it is imported. For example,
in the receipt “PN01”, enter the PEPSI product with the quantity of 10 and the
price of 10,000, then increase the quantity of PEPSI by 10 in the Product table and
update the new price to 10,000.
b. Update the quantity for the product when a sale is made. For example, in a
invoice “PB01” that sells a PEPSI product in quantity of 10, subtract this quantity
of PEPSI from the Product table.


14

Solution:
1. Draw ERD model:

Picture 1 ERD model



15

2. Relational model:

Picture 2 Relational model


16

3. Create database, table and insert datas:

Picture 3 Create database and tables (1)


17

Picture 4 Create database and tables (2)


18

Picture 5 Inserting datas


19

Result of example table Product:

Picture 6 Product table


4. Create required procedure: (Choosing option 2)

Picture 7 Procedure 2


20

Result:

Picture 8 Invoice table after executing procedure

5. Create required function: (Choosing option 1)

Picture 9 Function 1

Result:

Picture 10 R1’s row for comparison


13

Use SQL language to fulfill the following requirements for the above
relational model: (1)

3.

a. Create Database
b. Create table

c. Add at least 10 datarow to each table.
4.

Create a procedure for one of the following requirements: (1

point) a. a. Create a new receipt
b. Add data to the invoice
c. Add data to the product
5.

Create a function for one of the following requirements: (1

point) a. Indicate the total amount for a certain receipt.


b. Indicate the total amount for a certain invoice
6. Create a trigger for one of the following requirements: (1 point)
a. Update the quantity and price for the product when it is imported. For
example, in the receipt “PN01”, enter the PEPSI product with the quantity of 10
and the price of 10,000, then increase the quantity of PEPSI by 10 in the
Product table and update the new price to 10,000.
b. Update the quantity for the product when a sale is made. For example, in a
invoice “PB01” that sells a PEPSI product in quantity of 10, subtract this
quantity of PEPSI from the Product table.


14

Solution:
1. Draw ERD model:


Picture 1 ERD model


15


2. Relational model:

Picture 2 Relational model


×