Professional Documents
Culture Documents
Ass Dbi
Ass Dbi
ASSIGNMENT
DBI202 – DATABASE SYSTEM OF DORM
FPT UNIVERSITY
STUDENT NAME: PHAM NGOC HOA | SE05740
STUDENT NAME: NGUYEN HAI NAM | SE05123
Teacher: nguyen quynh chi
DBI202
TABLE OF CONTENTS
I) INTRODUCE THE PROBLEM…………………………………………………………………………………………….
1) DESCRIBE THE PROBLEM……………………………………………………………………………………………………….
2) MANAGEMENT OBJECTIVES…………………………………………………………………………………………………..
This report describes the structure and management of a database designed to manage the
information of a sample company. This database was developed to support the company's daily
business operations, including managing suppliers, customers, products, employees, orders, and order
details.
2. Database Structure
Each table in the database has a primary key that uniquely identifies each record. Additionally,
relationships between tables are defined through foreign keys.
4. Action Matters
Add Data: Data has been added to the tables, including information about suppliers, products,
customers, employees, and orders.
Updating Data: Some update operations were performed to calculate fields such as Total Amount in the
HoaDonChiTiet table and Total Amount in the HoaDon table.
Triggers and Procedures: A trigger has been created to update the Delivery Date when a new order is
added. A procedure is also created to get information about a product based on the product ID.
5. Normalization Process
Normalization was performed to ensure data integrity and minimize duplication. Normalization steps
include converting HoaDonChiTiet to 1NF, removing columns that do not match 2NF and 3NF.
6. Query Operations
DBI202
This database supports many query operations to retrieve, update and process data, including statistics
on sales, total number of products and total revenue.
A view has been created to generate an overview of orders, including information about customers,
products, and quantities sold.
8. Conclusion
The database is designed with a clear structure and supports the daily business activities of the sample
company. Normalization and primary key-foreign key rules have been implemented to ensure data
integrity and performance.
2) MANAGEMENT OBJECTIVES
-OUTPUT:
1.SUM TOTAL MONEY CUSTOMER
2. DISPLAY ITEMS
3.SUM TOTAL ITEMS
4.THE NUMBERS OF PRODUCTS
1. Bảng NhaCungCap:
Khóa Chính (Primary Key): MaNhaCC (nvarchar(10)) - Định danh duy nhất cho mỗi nhà cung cấp.
2. Bảng LoaiSanPham:
Primary Key: MaLoaiSP (nvarchar(10)) - Unique identifier for each product type.
Attributes:
3. SanPham Table:
Attributes:
4. NhanVien table:
Attributes:
GhiChu: Notes.
5. HoaDon Table:
Attributes:
6. HoaDonChiTiet table:
Primary Key: None, but MaHD and MaSP are used as foreign keys.
Attributes:
7. KhachHang Table:
Attributes:
Entity ENTITY
Relationship
Relationship
Connectivity (force) = 1
Connectivity = N
DBI202
3) INSERT CODE
1.CREATE TABLE
CREATE TABLE NhaCungCap(
MaNhaCC nvarchar(10) not null,
TenNhaCC nvarchar(40),
DiaChi nvarchar(60),
Phone nvarchar(24),
Fax nvarchar(24),
HomePage ntext
)
CREATE TABLE LoaiSanPham(
MaLoaiSP nvarchar(10) not null,
TenLoaiSP nvarchar(15),
MoTa ntext
)
CREATE TABLE SanPham(
MaSP nvarchar(10) not null,
DBI202
TenSP nvarchar(40),
MaNhaCC nvarchar(10),
MaLoaiSP nvarchar(10),
DVT nvarchar(20),
DonGia smallint,
SoLuong smallint,
SoLuongTT smallint,
Discontinued bit
)
CREATE TABLE NhanVien(
MaNV nvarchar(10) not null,
HoTen nvarchar(20),
ChucDanh nvarchar(30),
NgaySinh date,
NgayNhanViec date,
DiaChi nvarchar(50),
Phone nvarchar(20),
Photo image,
GhiChu ntext
)
CREATE TABLE HoaDon(
MaHD nvarchar(10) not null,
MaKH nvarchar(10),
MaNV nvarchar(10),
NgayLapHD smalldatetime,
NgayNhanHang smalldatetime,
Tien int,
Thue real,
TongSoTien int
)
CREATE TABLE HoaDonChiTiet(
MaHD nvarchar(10),
MaSP nvarchar(10),
DonGia int,
SoLuong smallint,
GiamGia real,
ThanhTien int
)
CREATE TABLE KhachHang(
MaKH nvarchar(10) not null,
TenKH nvarchar(30),
DiaChi ntext,
Phone nvarchar(12),
Email nvarchar(30)
)
ALTER TABLE NhaCungCap add constraint pk_MaNhaCC primary key(MaNhaCC)
ALTER TABLE LoaiSanPham add constraint pk_MaLoaiSP primary key(MaLoaiSP)
ALTER TABLE SanPham add constraint pk_MaSP primary key(MaSP)
ALTER TABLE NhanVien add constraint pk_MaNV primary key(MaNV)
ALTER TABLE HoaDon add constraint pk_MaHD primary key(MaHD)
ALTER TABLE KhachHang add constraint pk_MaKH primary key(MaKH)
ALTER TABLE SanPham add constraint fk_MaNhaCC foreign key (MaNhaCC) references
NhaCungCap(MaNhaCC),
constraint fk_MLoaiSP foreign key(MaLoaiSP) references LoaiSanPham(MaLoaiSP)
Alter table HoaDon add constraint fk_MaNV foreign key(MaNV) references NhanVien(MaNV),
constraint fk_MaKH foreign key(MaKH) references KhachHang(MaKH)
ALTER TABLE HoaDonChiTiet add constraint fk_MaHD foreign key(MaHD) references
HoaDon(MaHD),
DBI202