You are on page 1of 209

ĐH CÔNG NGHỆ THÔNG TIN

KHOA HỆ THỐNG THÔNG TIN


----------

Đồ Án OLAP

IS217.K13.HTCL

Nguyễn Quốc Cường MSSV: 17520304


Mạc Huy Tú MSSV: 17521196
Lớp: IS217.K13.HTCL
GVHD: Đỗ Thị Minh Phụng
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Mục Lục
1 Mô tả dữ liệu.......................................................................................................................... 6
1.1. Nguồn dữ liệu.................................................................................................................. 6
1.2. ERD database OLTP ..................................................................................................... 6
1.3. Mô tả database OLTP .................................................................................................... 6
1.3.1. Bảng: Sales.Customer ............................................................................................. 6
1.3.2. Bảng: Sales.CustomerCategories........................................................................... 9
1.3.3. Bảng: Sales.Invoices.............................................................................................. 10
1.3.4. Bảng: Sales.Invoicelines ....................................................................................... 13
1.3.5. Bảng: Application.Cities....................................................................................... 14
1.3.6. Bảng: Application.Countries ............................................................................... 15
1.3.7. Bảng: Application.StateProvinces ....................................................................... 16
1.3.8. Bảng : Applicaion.People ..................................................................................... 17
1.3.9. Bảng: Warehouse. StockItems ............................................................................. 23
1.3.10. Bảng: Warehouse.PackageTypes ..................................................................... 25
1.3.11. Bảng: Warehouse.Colors .................................................................................. 26
2 Mô tả database database warehouse ................................................................................. 27
2.1. Diagram database warehouse ..................................................................................... 27
2.2. Bảng: DimCustomers ................................................................................................... 27
2.3. Bảng: DimDates ............................................................................................................ 28
2.4. Bảng: DimSalesPersons ............................................................................................... 28
2.5. Bảng: DimStockItems .................................................................................................. 28
2.6. Bảng: FactSale .............................................................................................................. 28
3 SSIS database warehouse ................................................................................................... 30
3.1. Mô hình SSIS ................................................................................................................ 30
3.1.1. Reset Database ...................................................................................................... 30
4 Sequence Container: Load Dimension Tables ................................................................. 32
4.1. Load DimCustomer ...................................................................................................... 32
4.1.1. ADO NET Source: Customer Data Source ........................................................ 32
4.1.2. Sort Transformation Editor: Customer Sort ..................................................... 34
4.1.3. ADO NET Source: Customer Category Source ................................................. 35
4.1.4. Sort Transformation Editor: Customer Sort ..................................................... 36

2
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.1.5. Merge Join: Container Category và Customer .................................................. 37


4.1.6. Sort Transformation Editor: Customer & Category Sort ................................ 38
4.1.7. ADO NET Destination: Cities Source Data ........................................................ 39
4.1.8. Sort Transformation Editor: Cities Sort ............................................................ 40
4.1.9. Merge Join: Category & Customer và Cities ..................................................... 41
4.1.10. Sort Transformation Editor: Customer và City............................................. 42
4.1.11. ADO NET Soure: StateProvinceData ............................................................. 43
4.1.12. Sort Transformation Editor: StateProvinces Sort ......................................... 44
4.1.13. Merge Join: Category & Customer và Cities ................................................. 45
4.1.14. Sort Transformation Editor: Customer & City & StateProvince Sort ........ 47
4.1.15. ADO NET Source: Product & ProductCatogery Data .................................. 47
4.1.16. Sort Transformation Editor: StateProvinces Sort ......................................... 48
4.1.17. Merge Join: Customer & City & StateProvince và Country ........................ 49
4.1.18. Sort Transformation Editor: Customer & City & StateProvince & Country
Sort 51
4.1.19. ADO NET Destination: Load DimCustomers ................................................ 51
4.2. Load DimStockItems.................................................................................................... 53
4.2.1. ADO NET Source: StockItems Data ................................................................... 53
4.2.2. Sort Transformation Edit: StockItems Column ................................................ 54
4.2.3. ADO NET Source: PackageTypes Data .............................................................. 55
4.2.4. Sort Transformation Edit: PackageTypes Sort ................................................. 56
4.2.5. Merge Joins: StockItems & PackageTypes ........................................................ 56
4.2.6. Derived Column Tranformation: Transform Color Column ........................... 57
4.2.7. Sort Transformation Edit: StockItem & UnitPackage Sort ............................. 58
4.2.8. ADO NET Source: Colors Data ........................................................................... 59
4.2.9. Sort Transformation Edit: Colors Sort............................................................... 60
4.2.10. Merge join: StockItem & UnitPackage và Colors .......................................... 61
4.2.11. Derived Column Tranformation: Transform ColorName, Size Column .... 62
4.2.12. Sort Transformation Edit:Sort ........................................................................ 63
4.2.13. ADO NET Destination: DimStockItems ......................................................... 63
4.3. DimSalesPersons........................................................................................................... 65
4.3.1. ADO NET Source: People Data ........................................................................... 65
4.3.3. Sort Transformation: Sort ................................................................................... 67
4.3.4. ADO NET Destination: Load DimSalesPersons ................................................ 68

3
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.4. Load DimDate............................................................................................................... 69


4.4.1. Câu lệnh SQL: ....................................................................................................... 69
4.4.2. Sequence Container: Create Foreign Keys......................................................... 71
4.5. FactSales ........................................................................................................................ 72
4.5.1. ADO NET Destination: Invoice Source Data ..................................................... 73
4.5.2. ADO NET Destination: InvoiceLine Source....................................................... 74
4.5.3. Sort Transformation: Invoice Sort ...................................................................... 76
4.5.4. Sort Transformation: InvoiceLine Sort .............................................................. 77
4.5.5. Merge Joins: Invoice và InvoiceLine................................................................... 78
4.5.6. ADO NET Destination: DimStockItems Data .................................................... 80
4.5.7. Sort Transformation: DimStockItem Sort ......................................................... 81
4.5.8. SortTransformation: Sale Sort ............................................................................ 82
4.5.9. Merge Joins: Sale và DimStockItem ................................................................... 83
4.5.10. ADO NET Destination: DimSalesPersons Source .......................................... 85
4.5.11. SortTransformation: DimSalesPerson Sort .................................................... 86
4.5.12. SortTransformation: Sales & StockItem Sort ................................................ 87
4.5.13. Merge Joins: Sales & StockItem và DimSalesPerson .................................... 87
4.5.14. ADO NET Destination: DimCustomer Source ............................................... 89
4.5.15. SortTransformation: DimCustomers Sort ...................................................... 90
4.5.16. SortTransformation: Sales & StockItems & SalesPerson Sort ..................... 91
4.5.17. Merge Joins: Sales & StockItems & SalesPerson Sort và DimCustomers... 92
4.5.18. ADO NET Destination: DimDates Data .......................................................... 94
4.5.19. SortTransformation: DimDates Sort ............................................................... 95
4.5.20. SortTransformation: Sales & StockItems & SalesPerson & Customer Sort
96
4.5.21. Merge Joins: Sales & StockItems & SalesPerson & Customer và DimDates
97
4.5.22. SortTransformation: Sort ................................................................................ 99
4.6. Chạy chương trình ..................................................................................................... 101
5 SSAS ................................................................................................................................... 102
5.1. Tạo project mới .......................................................................................................... 102
5.2. Connect đến Data Sources ......................................................................................... 103
5.3. Điều chỉnh lại phân quyền của SQL Databasse....................................................... 105
5.4. Tạo Data Source View................................................................................................ 107

4
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

5.5. Tạo Dimessions ........................................................................................................... 109


5.5.1. DimDate ............................................................................................................... 110
5.6. Tạo Cubes.................................................................................................................... 114
5.7. Chỉnh sửa lại các thuộc tính của các bảng Dim ....................................................... 118
5.7.1. DimSalesPerson ................................................................................................... 118
5.7.2. DimCustomers ..................................................................................................... 122
5.7.3. Dim Stock Items .................................................................................................. 124
5.7.4. Dim Date .............................................................................................................. 127
5.8. Điều chỉnh Cubes (Sales.Cubes)................................................................................ 135
5.9. Tạo thêm độ đo Distinct Count ................................................................................. 140
6 Ngôn ngữ MDX: ................................................................................................................ 141
6.1. Câu 1: .......................................................................................................................... 141
6.2. Câu 2: .......................................................................................................................... 143
6.3. Câu 3: .......................................................................................................................... 146
6.4. Câu 4: .......................................................................................................................... 148
6.5. Câu 5: .......................................................................................................................... 151
6.6. Câu 6: .......................................................................................................................... 153
6.7. Câu 7: .......................................................................................................................... 156
6.8. Câu 8: .......................................................................................................................... 158
6.9. Câu 9: .......................................................................................................................... 161
6.10. Câu 10: ..................................................................................................................... 166
7 SSRS ................................................................................................................................... 170
7.1. Tạo project SSRS và thêm data source, dataset ...................................................... 170
7.2. Tạo report bảng với Grouping và Totals ................................................................. 173
7.3. Tạo Report thứ 2 ........................................................................................................ 178
7.4. Deploy project SSRS và đưa report lên server ........................................................ 181
8 Data Mining ....................................................................................................................... 182
8.1. Mô tả về dataset dùng để mining. ............................................................................. 182
8.2. Đổ dữ liệu vào SQL Server bằng công cụ SSIS ....................................................... 183
8.3. Data mining bằng công cụ SSAS trên Visual Studio .............................................. 186
8.4. Nhận xét kết quả sau khi Mining dữ liệu. ................................................................ 195
8.5. Đánh giá các thuật toán bằng Mining Accuracy Chart .......................................... 207

5
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

1 Mô tả dữ liệu
1.1. Nguồn dữ liệu
- Đây là một bộ dữ liệu mô tả về các quy trình sale của bán xe
đạp của một nhà máy
- Nguồn: https://github.com/Microsoft/sql-server-
samples/releases/tag/wide-world-importers-v1.0
(WideWorldImporters-Full.bak)
1.2. ERD database OLTP

Hình 1. Sơ đồ Diagram

1.3. Mô tả database OLTP


1.3.1. Bảng: Sales.Customer
X Name Data N Decription
CustomerID int Khóa chính cho các bản
ghi mô tả khách hàng.

6
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

(Cột nhận dạng / tự động


tăng)
CustomerName nvarchar(100) Họ tên khách hàng
BillToCustomerID int Mã số hóa đơn của
khách hàng
CustomerCategoryID int Mã số danh mục khách
hàng
BuyingGroupID int Nhóm mua của khách
hàng (tùy chọn)
PrimaryContactPersonID int Mã số liên hệ chính
AlternateContactPersonID int Mã số liên hệ thay thế
DeliveryMethodID int Mã số phương thức giao
hàng
DeliveryCityID int Mã số thành phố của
khách
PostalCityID int Mã số bưu điện của
khách hàng
CreditLimit decimal(18, 2) Hạng mức chi trả tín
dụng cho khách hàng
này (NULL nếu không
giới hạn)
AccountOpenedDate date Ngày mở tài khoản
StandardDiscountPercentage decimal(18, 3) Giảm giá cho khách
hàng
IsStatementSent bit Xác nhận gửi trả cho
khách hàng khi trả tiền
(Hay chỉ trả tiền trên
mỗi hóa đơn?)
IsOnCreditHold bit Kiểm tra xác thực của
khách hàng (Ngăn chặn
việc giao dịch tiếp theo
của khách hàng này)
PaymentDays int Số ngày thanh toán (số
lượng)
PhoneNumber nvarchar(20) Số điện thoại
FaxNumber nvarchar(20) Số fax
DeliveryRun nvarchar(5) Phương thức giao hàng
cho khách hàng
RunPosition nvarchar(5) Vị trí của khách hàng
WebsiteURL nvarchar(256) URL trang web của
khách hàng
DeliveryAddressLine1 nvarchar(60) Địa chỉ đường thứ 1
DeliveryAddressLine2 nvarchar(60) Địa chỉ đường thứ 2
DeliveryPostalCode nvarchar(10) Mã bưu điện giao hàng

7
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

DeliveryLocation geography Địa chỉ giao hàng


PostalAddressLine1 nvarchar(60) Địa chỉ bưu điện thứ 1
PostalAddressLine2 nvarchar(60) Địa chỉ bưu điện thứ 2
PostalPostalCode nvarchar(10) Địa chỉ bưu điện của
khách hàng khi gửi qua
thư
LastEditedBy int Lần thay đổi cuối cùng
ValidFrom datetime2(7) Có hiệu lực từ ngày
ValidTo datetime2(7) Có hiệu lực đến ngày

Liên kết:
Table Join Title/Name/Description
Sales.Customers.Buyin FK_Sales_Customers_BuyingGroupI
Sales.BuyingGro gGroupID = D_Sales_BuyingGroups
ups Sales.BuyingGroups.Bu Tham chiếu ràng buộc khóa ngoại
yingGroupID BuyingGroups.BuyingGroupID
Sales.Customers.Delive FK_Sales_Customers_DeliveryCityI
Application.Citie ryCityID = D_Application_Cities
s Application.Cities.CityITham chiếu ràng buộc khóa ngoại
D Cities.CityID
Sales.Customers.Postal FK_Sales_Customers_PostalCityID_
Application.Citie CityID = Application_Cities
s Application.Cities.CityITham chiếu ràng buộc khóa ngoại
D Cities.CityID
Sales.Customers.Custo FK_Sales_Customers_CustomerCate
merCategoryID = goryID_Sales_CustomerCategories
Sales.CustomerC
Sales.CustomerCategorie Tham chiếu ràng buộc khóa ngoại
ategories
s.CustomerCategoryID CustomerCategories.CustomerCateg
oryID
Sales.Customers.BillTo FK_Sales_Customers_BillToCustom
CustomerID = erID_Sales_Customers
Sales.Customers
Sales.Customers.Custo Tham chiếu ràng buộc khóa ngoại
merID Customers.CustomerID
Sales.Customers.Delive FK_Sales_Customers_DeliveryMeth
Application.Deli ryMethodID = odID_Application_DeliveryMethods
veryMethods Application.DeliveryMet Tham chiếu ràng buộc khóa ngoại
hods.DeliveryMethodID DeliveryMethods.DeliveryMethodID
Sales.Customers.Altern FK_Sales_Customers_AlternateCont
Application.Peop ateContactPersonID = actPersonID_Application_People
le Application.People.Pers Tham chiếu ràng buộc khóa ngoại
onID People.PersonID
Application.Peop Sales.Customers.LastEd FK_Sales_Customers_Application_P
le itedBy = eople

8
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Application.People.Pers Tham chiếu ràng buộc khóa ngoại


onID People.PersonID
Sales.Customers.Primar FK_Sales_Customers_PrimaryConta
Application.Peop yContactPersonID = ctPersonID_Application_People
le Application.People.Pers Tham chiếu ràng buộc khóa ngoại
onID People.PersonID
Sales.Customers.BillTo FK_Sales_Customers_BillToCustom
CustomerID = erID_Sales_Customers
Sales.Customers
Sales.Customers.Custo Tham chiếu ràng buộc khóa ngoại
merID Customers.CustomerID
Sales.CustomerTransacti FK_Sales_CustomerTransactions_Cu
Sales.CustomerT ons.CustomerID = stomerID_Sales_Customers
ransactions Sales.Customers.Custo Tham chiếu ràng buộc khóa ngoại
merID Customers.CustomerID
Sales.Invoices.BillToCu FK_Sales_Invoices_BillToCustomer
stomerID = ID_Sales_Customers
Sales.Invoices
Sales.Customers.Custo Tham chiếu ràng buộc khóa ngoại
merID Customers.CustomerID
Sales.Invoices.Customer FK_Sales_Invoices_CustomerID_Sal
ID = es_Customers
Sales.Invoices
Sales.Customers.Custo Tham chiếu ràng buộc khóa ngoại
merID Customers.CustomerID
Sales.Orders.CustomerI FK_Sales_Orders_CustomerID_Sale
D= s_Customers
Sales.Orders
Sales.Customers.Custo Tham chiếu ràng buộc khóa ngoại
merID Customers.CustomerID
Sales.SpecialDeals.Cust FK_Sales_SpecialDeals_CustomerID
Sales.SpecialDea omerID = _Sales_Customers
ls Sales.Customers.Custo Tham chiếu ràng buộc khóa ngoại
merID Customers.CustomerID
Warehouse.StockItemTr FK_Warehouse_StockItemTransacti
ansactions.CustomerID ons_CustomerID_Sales_Customers
Warehouse.Stock
= Tham chiếu ràng buộc khóa ngoại
ItemTransactions
Sales.Customers.Custo Customers.CustomerID
merID

Khóa độc nhất (unique key)


Columns Name/Description
CustomerID PK_Sales_Customers
(Khóa chính)
CustomerName UQ_Sales_Customers_CustomerName
(Khóa độc nhất)

1.3.2. Bảng: Sales.CustomerCategories

9
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

X Name Data N Decription


CustomerCategoryID int Khóa chính danh mục
khách hàng.
(Cột nhận dạng)
CustomerCategoryName nvarchar(50) Tên danh mục khách hàng
LastEditedBy int Lần chỉnh sửa cuối cùng
ValidFrom datetime2(7) Có hiệu lực từ ngày
ValidTo datetime2(7) Có hiệu lực đến ngày

Liên kết:
Table Join Title/Name/Description
Applicatio Sales.CustomerCategories. FK_Sales_CustomerCategories_Applicati
n.People LastEditedBy = on_People
Application.People.PersonI Tham chiếu ràng buộc khóa ngoại
D People.PersonID
Sales.Cust Sales.Customers.CustomerC FK_Sales_CustomerCategories_Applicati
omers ategoryID on_People
= Sales.CustomerCategori Tham chiếu ràng buộc khóa ngoại
es.CustomerCategoryID People.PersonID
Sales.Spe Sales.Customers.CustomerC FK_Sales_SpecialDeals_CustomerCateg
cialDeals ategoryID oryID_Sales_CustomerCategories
= Sales.CustomerCategori Tham chiếu ràng buộc khóa ngoại
es.CustomerCategoryID CustomerCategories.CustomerCategoryI
D

Khóa độc nhất (unique key)


Columns Name/Description
CustomerCategoryID PK_Sales_CustomerCategories (Khóa chính)
CustomerCategoryNam UQ_Sales_CustomerCategories_CustomerCategoryNam
e e (Khóa độc nhất)

1.3.3. Bảng: Sales.Invoices


X Name Data N Decription
InvoiceID int Khóa chính hóa đơn.
(Cột nhận dạng)
CustomerID int Tên khách hàng
BillToCustomerID int Mã hóa đơn đến
khách hàng
OrderID int Mã hàng hóa
DeliveryMethodID int Mã vận chuyển
ContactPersonID int Mã liên lạc

10
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

AccountsPersonID int Mã tài khoản


SalespersonPersonID int Mã người bán hàng
PackedByPersonID int Mã kiện hàng
InvoiceDate date Ngày của hóa đơn
CustomerPurchaseOrderNumber nvarchar(20) Purchase Order
Number received
from customer
IsCreditNote bit Đây có phải là một
ghi chú tín dụng (chứ
không phải là một hóa
đơn)
CreditNoteReason nvarchar(MAX) Lý do rằng ghi chú tín
dụng này cần được
tạo ra (nếu có)
Comments nvarchar(MAX) Mọi ý kiến liên quan
đến hóa đơn này (gửi
cho khách hàng)
DeliveryInstructions nvarchar(MAX) Bất kỳ ý kiến liên
quan đến giao hàng
(gửi cho khách hàng)
InternalComments nvarchar(MAX) Bất kỳ ý kiến nội bộ
liên quan đến hóa đơn
này (không được gửi
cho khách hàng)
TotalDryItems int Tổng số hàng khô
(thông tin cho tài xế
giao hàng)
TotalChillerItems int Tổng số gói chiller
(thông tin cho tài xế
giao hàng)
DeliveryRun nvarchar(5) Giao hàng chạy cho
lô hàng này
RunPosition nvarchar(5) Vị trí trong giao hàng
chạy cho lô hàng này
ReturnedDeliveryData nvarchar(MAX) Dữ liệu có cấu trúc
JSON được trả về từ
các thiết bị phân phối
cho việc phân phối
được thực hiện trực
tiếp bởi tổ chức
ConfirmedDeliveryTime datetime2(7) Xác nhận ngày và
thời gian giao hàng
được quảng cáo từ dữ
liệu phân phối JSON

11
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

ConfirmedReceivedBy nvarchar(4000) Xác nhận người nhận


được quảng bá từ dữ
liệu phân phối JSON
LastEditedBy int Lần thay đổi cuối
LastEditedWhen datetime2(7) Lần thay đổi cuối
(thời gian)

Liên kết:
Table Join Title/Name/Description
Sales.Customers Sales.Invoices.Customer FK_Sales_Invoices_CustomerID_Sal
ID = es_Customers
Sales.Customers.Custom Tham chiếu ràng buộc khóa ngoại
erID Customers.CustomerID
Sales.Customers Sales.Invoices.BillToCu FK_Sales_Invoices_BillToCustomer
stomerID = ID_Sales_Customers
Sales.Customers.Custom Tham chiếu ràng buộc khóa ngoại
erID Customers.CustomerID
Application.Deliv Sales.Invoices.Delivery FK_Sales_Invoices_DeliveryMethod
eryMethods MethodID = ID_Application_DeliveryMethods
Application.DeliveryMet Tham chiếu ràng buộc khóa ngoại
hods.DeliveryMethodID DeliveryMethods.DeliveryMethodI
D
Sales.Orders Sales.Invoices.OrderID FK_Sales_Invoices_OrderID_Sales_
= Sales.Orders.OrderID Orders
Tham chiếu ràng buộc khóa ngoại
Orders.OrderID
Application.Peop Sales.Invoices.PackedBy FK_Sales_Invoices_PackedByPerson
le PersonID = ID_Application_People
Application.People.Perso Tham chiếu ràng buộc khóa ngoại
nID People.PersonID
Application.Peop Sales.Invoices.Salespers FK_Sales_Invoices_SalespersonPers
le onPersonID = onID_Application_People
Application.People.Perso Tham chiếu ràng buộc khóa ngoại
nID People.PersonID
Application.Peop Sales.Invoices.Accounts FK_Sales_Invoices_AccountsPerson
le PersonID = ID_Application_People
Application.People.Perso Tham chiếu ràng buộc khóa ngoại
nID People.PersonID
Application.Peop Sales.Invoices.LastEdite FK_Sales_Invoices_Application_Peo
le dBy = ple
Application.People.Perso Tham chiếu ràng buộc khóa ngoại
nID People.PersonID
Application.Peop Sales.Invoices.ContactPe FK_Sales_Invoices_ContactPersonI
le rsonID = D_Application_People

12
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Application.People.Perso Tham chiếu ràng buộc khóa ngoại


nID People.PersonID
Sales.CustomerTr Sales.CustomerTransacti FK_Sales_CustomerTransactions_In
ansactions ons.InvoiceID = voiceID_Sales_Invoices
Sales.Invoices.InvoiceID Tham chiếu ràng buộc khóa ngoại
Invoices.InvoiceID
Sales.InvoiceLine Sales.InvoiceLines.Invoi FK_Sales_InvoiceLines_InvoiceID_
s ceID Sales_Invoices
= Sales.Invoices.Invoice Tham chiếu ràng buộc khóa ngoại
ID Invoices.InvoiceID

Warehouse.Stock Warehouse.StockItemTra FK_Warehouse_StockItemTransacti


ItemTransactions nsactions.InvoiceID = ons_InvoiceID_Sales_Invoices
Sales.Invoices.InvoiceID Tham chiếu ràng buộc khóa ngoại
Invoices.InvoiceID

Khóa độc nhất (unique key)


Columns Name/Description
InvoiceID PK_Sales_Invoices
(Khóa chính)

1.3.4. Bảng: Sales.Invoicelines


X Name Data N Decription
InvoiceLineID int Khóa chính dòng hóa
đơn.
(Cột nhận dạng)
InvoiceID int Mã hóa đơn
StockItemID int Mã kho hàng
Description nvarchar(100) Miêu tả
PackageTypeID int Mã loại gói
Quantity int Định lượng
UnitPrice decimal(18, 2) Đơn giá
TaxRate decimal(18, 3) Thuế suất được áp
dụng
TaxAmount decimal(18, 2) Số tiền thuế được tính
LineProfit decimal(18, 2) Lợi nhuận được thực
hiện trên chi tiết đơn
hàng này với giá hiện
tại
ExtendedPrice decimal(18, 2) Chi phí thêm
LastEditedBy int Lần thay đổi cuối
LastEditedWhen datetime2(7) Lần thay đổi cuối
(thời gian)

13
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Liên kết:
Table Join Title/Name/Description
Sales.Invoices Sales.InvoiceLines.Invo FK_Sales_InvoiceLines_InvoiceID_Sale
iceID = s_Invoices
Sales.Invoices.InvoiceI Tham chiếu ràng buộc khóa ngoại
D Invoices.InvoiceID
Warehouse.Pa Sales.InvoiceLines.Pac FK_Sales_InvoiceLines_PackageTypeI
ckageTypes kageTypeID = D_Warehouse_PackageTypes
Warehouse.PackageTyp Tham chiếu ràng buộc khóa ngoại
es.PackageTypeID PackageTypes.PackageTypeID
Application.Pe Sales.InvoiceLines.Last FK_Sales_InvoiceLines_Application_Pe
ople EditedBy = ople
Application.People.Pers Tham chiếu ràng buộc khóa ngoại
onID People.PersonID
Warehouse.Sto Sales.InvoiceLines.Stoc FK_Sales_InvoiceLines_StockItemID_
ckItems kItemID = Warehouse_StockItems
Warehouse.StockItems. Tham chiếu ràng buộc khóa ngoại
StockItemID StockItems.StockItemID

Khóa độc nhất (unique key)


Columns Name/Description
InvoiceLineID PK_Sales_InvoiceLines
(Khóa chính)

1.3.5. Bảng: Application.Cities


X Name Data N Decription
CityID int Khóa chính thành phố.
(Cột nhận dạng / tự động tăng)
CityName nvarchar(50) Tên thành phố
StateProvinceID int Mã bang hoặc vùng của thành phố
Location geography Vị trí thành phố
LatestRecordedPop bigint Thống kê dân số lần gần nhất
ulation
LastEditedBy int Lần thay đổi cuối
ValidFrom datetime2(7) Có hiệu lực từ ngày
ValidTo datetime2(7) Có hiệu lực đến ngày
Liên kết:
Table Join Title/Name/Description
Application.Peo Application.Cities.LastE FK_Application_Cities_Application_
ple ditedBy = People

14
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Application.People.Perso Tham chiếu ràng buộc khóa


nID ngoạiPeople.PersonID
Application.Cities.State FK_Application_Cities_StateProvinc
Application.Stat ProvinceID = eID_Application_StateProvinces
eProvinces Application.StateProvinc Tham chiếu ràng buộc khóa
es.StateProvinceID ngoạiStateProvinces.StateProvinceID
Sales.Customers.Deliver FK_Sales_Customers_DeliveryCityID
yCityID = _Application_Cities
Sales.Customers
Application.Cities.CityI Tham chiếu ràng buộc khóa
D ngoạiCities.CityID
Sales.Customers.PostalCi FK_Sales_Customers_PostalCityID_
tyID = Application_Cities
Sales.Customers
Application.Cities.CityI Tham chiếu ràng buộc khóa
D ngoạiCities.CityID
Purchasing.Suppliers.Del FK_Purchasing_Suppliers_DeliveryCi
Purchasing.Sup iveryCityID = tyID_Application_Cities
pliers Application.Cities.CityI Tham chiếu ràng buộc khóa
D ngoạiCities.CityID
Purchasing.Suppliers.Pos FK_Purchasing_Suppliers_DeliveryCi
Purchasing.Sup talCityID = tyID_Application_Cities
pliers Application.Cities.CityI Tham chiếu ràng buộc khóa
D ngoạiCities.CityID
Application.SystemPara FK_Purchasing_Suppliers_DeliveryCi
Application.Syst meters.DeliveryCityID = tyID_Application_Cities
emParameters Application.Cities.CityI Tham chiếu ràng buộc khóa
D ngoạiCities.CityID
Application.SystemPara FK_Purchasing_Suppliers_DeliveryCi
Application.Syst meters.PostalCityID = tyID_Application_Cities
emParameters Application.Cities.CityI Tham chiếu ràng buộc khóa
D ngoạiCities.CityID

Khóa độc nhất (unique key)


Columns Name/Description
CityID PK_Application_Cities (Khóa chính)

1.3.6. Bảng: Application.Countries


X Name Data N Decription
CountryID int Khóa chính đất nước.
(Cột nhận dạng)
CountryName nvarchar(60) Tên đất nước
FormalName nvarchar(60) Tên chính thức đầy đủ của đất nước
theo thỏa thuận của Liên Hợp Quốc

15
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

IsoAlpha3Code nvarchar(3) Mã 3 chữ cái được gán cho quốc gia


theo ISO
IsoNumericCode int Mã số được gán cho quốc gia theo
ISO
CountryType nvarchar(20) Loại quốc gia hoặc khu vực hành
chính
LatestRecordedPopula bigint Thống kê dân số lần gần nhất
tion
Continent nvarchar(30) Tên lục địa
Region nvarchar(30) Vùng
Subregion nvarchar(30) Khu vực
Border geography Biên giới
LastEditedBy int Lần thay đổi cuối
ValidFrom datetime2(7) Có hiệu lực từ ngày
ValidTo datetime2(7) Có hiệu lực đến ngày
Liên kết:
Table Join Title/Name/Description
Application.Count FK_Application_Countries_Application_P
Application.Peo ries.LastEditedBy = eople
ple Application.People. Tham chiếu ràng buộc khóa ngoại
PersonID People.PersonID
Application.StatePr FK_Application_StateProvinces_CountryI
ovinces.CountryID D_Application_Countries
Application.Stat
= Tham chiếu ràng buộc khóa ngoại
eProvinces
Application.Count Countries.CountryID
ries.CountryID

Khóa độc nhất (unique key)


Columns Name/Description
CountryID PK_Application_Countries
(Khóa chính)
CountryName UQ_Application_Countries_CountryName
(Khóa độc nhất)
FormalName UQ_Application_Countries_FormalName
(Khóa độc nhất)

1.3.7. Bảng: Application.StateProvinces


X Name Data N Decription
StateProvinceID int Khóa chính Tỉnh/bang.
(Cột nhận dạng)
StateProvinceCode nvarchar(5) Mã phổ biến cho tiểu bang hoặc tỉnh
này (chẳng hạn như WA -
Washington cho Hoa Kỳ)

16
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

StateProvinceName nvarchar(50) Tên chính thức của bang hoặc tỉnh


CountryID int Mã đất nước
SalesTerritory nvarchar(50) Nơi bán hàng ở bang/tỉnh
Border geography Biên giới
LatestRecordedPop bigint Thống kê dân số lần gần nhất
ulation
LastEditedBy int Lần thay đổi cuối
ValidFrom datetime2(7) Có hiệu lực từ ngày
ValidTo datetime2(7) Có hiệu lực đến ngày
Liên kết:
Table Join Title/Name/Description
Application.StateProvin FK_Application_StateProvinces_Countr
Application. ces.CountryID = yID_Application_Countries
Countries Application.Countries.Co Tham chiếu ràng buộc khóa ngoại
untryID Countries.CountryID
Application.StateProvin FK_Application_StateProvinces_Applic
Application. ces.LastEditedBy = ation_People
People Application.People.Person Tham chiếu ràng buộc khóa ngoại
ID People.PersonID
Application.Cities.StatePr FK_Application_Cities_StateProvinceID
Application. ovinceID = _Application_StateProvinces
Cities Application.StateProvin Tham chiếu ràng buộc khóa ngoại
ces.StateProvinceID StateProvinces.StateProvinceID

Khóa độc nhất (unique key)


Columns Name/Description
StateProvinceID PK_Application_StateProvinces
(Khóa chính)
StateProvinceName UQ_Application_StateProvinces_StateProvinceName
(Khóa độc nhất)

1.3.8. Bảng : Applicaion.People


X Name Data N Decription
PersonID int Khóa bảng người
(Cột nhận dạng)
FullName nvarchar(50) Họ tên
PreferredName nvarchar(50) Biệt danh
SearchName nvarchar(101) Tên để xây dựng tìm kiếm toàn văn
bản trên (cột được tính toán)
IsPermittedToLogo bit Người này có được phép đăng nhập
n không?
LogonName nvarchar(50) Tên đăng nhập

17
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

IsExternalLogonPr bit Là mã thông báo đăng nhập được


ovider cung cấp bởi một hệ thống?
HashedPassword varbinary(MAX) Hash mật khẩu cho người dùng
IsSystemUser bit Hiện tại có được phép truy cập trực
tuyến không?
IsEmployee bit Người này có phải là nhân viên
không?
IsSalesperson bit Có phải người này là nhân viên bán
hàng?
UserPreferences nvarchar(MAX) Tùy chọn người dùng liên quan đến
trang web (giữ dữ liệu JSON)
PhoneNumber nvarchar(20) Số điện thoại
FaxNumber nvarchar(20) Số Fax
EmailAddress nvarchar(256) Địa chỉ email
Photo varbinary(MAX) Ảnh của khách hàng
CustomFields nvarchar(MAX) Các lĩnh vực tùy chỉnh cho nhân
viên và nhân viên bán hàng
OtherLanguages nvarchar(MAX) Ngôn ngữ khác
LastEditedBy int Lần thay đổi cuối
ValidFrom datetime2(7) Có hiệu lực từ ngày
ValidTo datetime2(7) Có hiệu lực đến ngày
Liên kết:
Table Join Title/Name/Description
Application.People FK_Application_People_Application_Peo
Application.Peo .LastEditedBy = ple
ple Application.People. Tham chiếu ràng buộc khóa ngoại
PersonID People.PersonID
Application.People FK_Application_People_Application_Peo
Application.Peo .LastEditedBy = ple
ple Application.People. Tham chiếu ràng buộc khóa ngoại
PersonID People.PersonID
Sales.BuyingGroups FK_Sales_BuyingGroups_Application_Pe
Sales.BuyingGro .LastEditedBy = ople
ups Application.People Tham chiếu ràng buộc khóa ngoại
.PersonID People.PersonID
Application.Cities.L FK_Application_Cities_Application_Peop
Application.Citie astEditedBy = le
s Application.People Tham chiếu ràng buộc khóa ngoại
.PersonID People.PersonID
Warehouse.Colors.L FK_Warehouse_Colors_Application_Peop
Warehouse.Colo astEditedBy = le
rs Application.People Tham chiếu ràng buộc khóa ngoại
.PersonID People.PersonID
Application.Cou Application.Countri FK_Application_Countries_Application_P
ntries es.LastEditedBy = eople

18
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Application.People Tham chiếu ràng buộc khóa ngoại


.PersonID People.PersonID
Sales.CustomerCate FK_Sales_CustomerCategories_Applicati
gories.LastEditedBy on_People
Sales.CustomerC
= Tham chiếu ràng buộc khóa ngoại
ategories
Application.People People.PersonID
.PersonID
Sales.Customers.Alt FK_Sales_Customers_AlternateContactPe
ernateContactPerson rsonID_Application_People
Sales.Customers ID = Tham chiếu ràng buộc khóa ngoại
Application.People People.PersonID
.PersonID
Sales.Customers.La FK_Sales_Customers_Application_People
stEditedBy = Tham chiếu ràng buộc khóa ngoại
Sales.Customers
Application.People People.PersonID
.PersonID
Sales.Customers.Pri FK_Sales_Customers_PrimaryContactPers
maryContactPersonI onID_Application_People
Sales.Customers D = Tham chiếu ràng buộc khóa ngoại
Application.People People.PersonID
.PersonID
Sales.CustomerTran FK_Sales_CustomerTransactions_Applica
sactions.LastEdited tion_People
Sales.CustomerT
By = Tham chiếu ràng buộc khóa ngoại
ransactions
Application.People People.PersonID
.PersonID
Application.Deliver FK_Application_DeliveryMethods_Applic
yMethods.LastEdite ation_People
Application.Deli
dBy Tham chiếu ràng buộc khóa ngoại
veryMethods
= Application.Peop People.PersonID
le.PersonID
FK_Sales_InvoiceLines_Application_Peo
Sales.InvoiceLines. ple
Sales.InvoiceLin LastEditedBy Tham chiếu ràng buộc khóa ngoại
es = Application.Peop People.PersonID
le.PersonID

Sales.Invoices.Acco FK_Sales_Invoices_AccountsPersonID_A
untsPersonID pplication_People
Sales.Invoices
= Application.Peop Tham chiếu ràng buộc khóa ngoại
le.PersonID People.PersonID
Sales.Invoices.LastEdit FK_Sales_Invoices_Application_People
edBy Tham chiếu ràng buộc khóa ngoại
Sales.Invoices
= Application.People People.PersonID
.PersonID

19
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

FK_Sales_Invoices_ContactPersonID_Ap
Sales.Invoices.Cont plication_People
actPersonID Tham chiếu ràng buộc khóa ngoại
Sales.Invoices
= Application.Peop People.PersonID
le.PersonID

FK_Sales_Invoices_PackedByPersonID_
Sales.Invoices.Pack Application_People
edByPersonID Tham chiếu ràng buộc khóa ngoại
Sales.Invoices
= Application.Peop People.PersonID
le.PersonID

FK_Sales_Invoices_SalespersonPersonID
Sales.Invoices.Sales _Application_People
personPersonID Tham chiếu ràng buộc khóa ngoại
Sales.Invoices
= Application.Peop People.PersonID
le.PersonID

Sales.OrderLines.La FK_Sales_OrderLines_Application_Peopl
stEditedBy e
Sales.OrderLines
= Application.Peop Tham chiếu ràng buộc khóa ngoại
le.PersonID People.PersonID
Sales.Orders.LastEd FK_Sales_Orders_Application_People
itedBy Tham chiếu ràng buộc khóa ngoại
Sales.Orders
= Application.Peop People.PersonID
le.PersonID
Sales.Orders.Contac FK_Sales_Orders_ContactPersonID_Appl
tPersonID ication_People
Sales.Orders
= Application.Peop Tham chiếu ràng buộc khóa ngoại
le.PersonID People.PersonID
Sales.Orders.Picked FK_Sales_Orders_PickedByPersonID_Ap
ByPersonID plication_People
Sales.Orders
= Application.Peop Tham chiếu ràng buộc khóa ngoại
le.PersonID People.PersonID
Sales.Orders.Salesp FK_Sales_Orders_SalespersonPersonID_
ersonPersonID Application_People
Sales.Orders
= Application.Peop Tham chiếu ràng buộc khóa ngoại
le.PersonID People.PersonID
Warehouse.Package FK_Warehouse_PackageTypes_Applicati
Warehouse.Pack Types.LastEditedBy on_People
ageTypes = Application.Peop Tham chiếu ràng buộc khóa ngoại
le.PersonID People.PersonID
Application.Paymen FK_Application_PaymentMethods_Applic
Application.Pay
tMethods.LastEdite ation_People
mentMethods
dBy

20
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

= Application.Peop Tham chiếu ràng buộc khóa ngoại


le.PersonID People.PersonID
Application.Paymen FK_Purchasing_PurchaseOrderLines_App
tMethods.LastEdite lication_People
Purchasing.Purc
dBy Tham chiếu ràng buộc khóa ngoại
haseOrderLines
= Application.Peop People.PersonID
le.PersonID
Purchasing.Purchase FK_Purchasing_PurchaseOrders_Applicat
Orders.LastEditedB ion_People
Purchasing.Purc
y Tham chiếu ràng buộc khóa ngoại
haseOrders
= Application.Peop People.PersonID
le.PersonID
Purchasing.Purchas FK_Purchasing_PurchaseOrders_ContactP
eOrders.ContactPers ersonID_Application_People
Purchasing.Purc
onID Tham chiếu ràng buộc khóa ngoại
haseOrders
= Application.Peop People.PersonID
le.PersonID
Sales.SpecialDeals. FK_Sales_SpecialDeals_Application_Peo
Sales.SpecialDea LastEditedBy ple
ls = Application.Peop Tham chiếu ràng buộc khóa ngoại
le.PersonID People.PersonID
Application.StatePr FK_Application_StateProvinces_Applicati
ovinces.LastEditedB on_People
Application.Stat
y Tham chiếu ràng buộc khóa ngoại
eProvinces
= Application.Peop People.PersonID
le.PersonID
Warehouse.StockGr FK_Warehouse_StockGroups_Application
Warehouse.Stoc oups.LastEditedBy _People
kGroups = Application.Peop Tham chiếu ràng buộc khóa ngoại
le.PersonID People.PersonID
Warehouse.StockIte FK_Warehouse_StockItemHoldings_Appl
mHoldings.LastEdit ication_People
Warehouse.Stoc
edBy Tham chiếu ràng buộc khóa ngoại
kItemHoldings
= Application.Peop People.PersonID
le.PersonID
Warehouse.StockIte FK_Warehouse_StockItems_Application_
Warehouse.Stoc ms.LastEditedBy People
kItems = Application.Peop Tham chiếu ràng buộc khóa ngoại
le.PersonID People.PersonID
Warehouse.StockIte FK_Warehouse_StockItemStockGroups_
Warehouse.Stoc mStockGroups.Last Application_People
kItemStockGrou EditedBy Tham chiếu ràng buộc khóa ngoại
ps = Application.Peop People.PersonID
le.PersonID

21
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Warehouse.StockIte FK_Warehouse_StockItemTransactions_A
Warehouse.Stoc mTransactions.Last pplication_People
kItemTransactio EditedBy Tham chiếu ràng buộc khóa ngoại
ns = Application.Peop People.PersonID
le.PersonID
Purchasing.Supplier FK_Purchasing_SupplierCategories_Appli
Categories.LastEdit cation_People
Purchasing.Supp
edBy Tham chiếu ràng buộc khóa ngoại
lierCategories
= Application.Peop People.PersonID
le.PersonID
Purchasing.Supplier FK_Purchasing_Suppliers_AlternateConta
s.AlternateContactP ctPersonID_Application_People
Purchasing.Supp
ersonID Tham chiếu ràng buộc khóa ngoại
liers
= Application.Peop People.PersonID
le.PersonID
Purchasing.Supplier FK_Purchasing_Suppliers_Application_Pe
Purchasing.Supp s.LastEditedBy ople
liers = Application.Peop Tham chiếu ràng buộc khóa ngoại
le.PersonID People.PersonID
Purchasing.Supplier FK_Purchasing_Suppliers_PrimaryContac
s.PrimaryContactPe tPersonID_Application_People
Purchasing.Supp
rsonID Tham chiếu ràng buộc khóa ngoại
liers
= Application.Peop People.PersonID
le.PersonID
Purchasing.Supplier FK_Purchasing_SupplierTransactions_Ap
Transactions.LastEd plication_People
Purchasing.Supp
itedBy Tham chiếu ràng buộc khóa ngoại
lierTransactions
= Application.Peop People.PersonID
le.PersonID
Application.System FK_Application_SystemParameters_Appli
Parameters.LastEdit cation_People
Application.Syst
edBy Tham chiếu ràng buộc khóa ngoại
emParameters
= Application.Peop People.PersonID
le.PersonID
Application.Transac FK_Application_TransactionTypes_Appli
tionTypes.LastEdite cation_People
Application.Tran
dBy Tham chiếu ràng buộc khóa ngoại
sactionTypes
= Application.Peop People.PersonID
le.PersonID

Khóa độc nhất (unique key)


Columns Name/Description
PersonID PK_Application_People
(Khóa chính)

22
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

1.3.9. Bảng: Warehouse. StockItems


X Name Data N Decription
StockItemID int Khóa chính hàng tồn kho.
(Cột nhận dạng / tự động tăng)
StockItemName nvarchar(100) Tên hàng tồn kho
SupplierID int Khóa nhà cung cấp
ColorID int Mã màu
UnitPackageID int Khóa đơn vị gói hàng
OuterPackageID int Khóa kiện hàng (ví dụ như thùng,
hộp, v.v.)
Brand nvarchar(50) Nhãn hiệu
Size nvarchar(20) Kích cỡ
LeadTimeDays int Số ngày giao hàng
QuantityPerOuter int Số lượng sản phẩm trong 1 kiện
hàng
IsChillerStock bit Có cần giữ trong máy lạnh không
Barcode nvarchar(50) Barcode của gói hàng
TaxRate decimal(18, 3) Thuế suất được áp dụng
UnitPrice decimal(18, 2) Đơn giá
RecommendedReta decimal(18, 2) Giá bán lẻ đề xuất cho mặt hàng này
ilPrice
TypicalWeightPer decimal(18, 3) Khối lượng (đã đóng gói)
Unit
MarketingCommen nvarchar(MAX) Nhận xét tiếp thị cho mặt hàng này
ts (được chia sẻ từ bên ngoài)
InternalComments nvarchar(MAX) Nhận xét nội bộ (không được đưa ra
bên ngoài)
Photo varbinary(MAX) Ảnh
CustomFields nvarchar(MAX) Các trường tùy chỉnh được thêm
bởi người dùng hệ thống
Tags nvarchar(MAX) Thẻ quảng cáo được liên kết với
mục hàng này (mảng JSON được
truy xuất từ CustomFields)
SearchDetails nvarchar(MAX) Kết các cột tìm kiếm lại thành 1
dòng
LastEditedBy int Lần thay đổi cuối
ValidFrom datetime2(7) Có hiệu lực từ ngày
ValidTo datetime2(7) Có hiệu lực đến ngày
Liên kết:
Table Join Title/Name/Description

23
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Warehouse.PackageT FK_Warehouse_StockItems_ColorID_
Warehouse.Colo ypes.LastEditedBy = Warehouse_Colors
rs Application.People.Pers Foreign key constraint referencing
onID Colors.ColorID
Sales.InvoiceLines.Pac FK_Warehouse_StockItems_OuterPac
Warehouse.Pack kageTypeID = kageID_Warehouse_PackageTypes
ageTypes Warehouse.PackageT Foreign key constraint referencing
ypes.PackageTypeID PackageTypes.PackageTypeID
Sales.OrderLines.Packa FK_Warehouse_StockItems_UnitPacka
Warehouse.Pack geTypeID = geID_Warehouse_PackageTypes
ageTypes Warehouse.PackageT Foreign key constraint referencing
ypes.PackageTypeID PackageTypes.PackageTypeID
Purchasing.PurchaseOr FK_Warehouse_StockItems_Applicati
derLines.PackageTypeI on_People
Application.Peop
D Foreign key constraint referencing
le
= Warehouse.Package People.PersonID
Types.PackageTypeID
Warehouse.StockItems. FK_Warehouse_StockItems_SupplierI
Purchasing.Supp OuterPackageID = D_Purchasing_Suppliers
liers Warehouse.PackageT Foreign key constraint referencing
ypes.PackageTypeID Suppliers.SupplierID
Warehouse.StockItems. FK_Sales_InvoiceLines_StockItemID_
Sales.InvoiceLin UnitPackageID = Warehouse_StockItems
es Warehouse.PackageT Foreign key constraint referencing
ypes.PackageTypeID StockItems.StockItemID
Sales.OrderLines.Stock FK_Sales_OrderLines_StockItemID_
ItemID Warehouse_StockItems
Sales.OrderLines
= Warehouse.StockIte Foreign key constraint referencing
ms.StockItemID StockItems.StockItemID
Purchasing.PurchaseOr FK_Purchasing_PurchaseOrderLines_S
Purchasing.Purc derLines.StockItemID tockItemID_Warehouse_StockItems
haseOrderLines = Warehouse.StockIte Foreign key constraint referencing
ms.StockItemID StockItems.StockItemID
Sales.SpecialDeals.Stoc FK_Sales_SpecialDeals_StockItemID_
Sales.SpecialDea kItemID Warehouse_StockItems
ls = Warehouse.StockIte Foreign key constraint referencing
ms.StockItemID StockItems.StockItemID
Warehouse.StockItemH FK_Warehouse_StockItemHoldings_St
Warehouse.Stoc oldings.StockItemID ockItemID_Warehouse_StockItems
kItemHoldings = Warehouse.StockIte Foreign key constraint referencing
ms.StockItemID StockItems.StockItemID
Warehouse.Stoc Warehouse.StockItemS FK_Warehouse_StockItemStockGroup
kItemStockGrou tockGroups.StockItemI s_StockItemID_Warehouse_StockItem
ps D s

24
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

= Warehouse.StockIte Foreign key constraint referencing


ms.StockItemID StockItems.StockItemID
Warehouse.StockItemT FK_Warehouse_StockItemTransaction
Warehouse.Stoc ransactions.StockItemI s_StockItemID_Warehouse_StockItem
kItemTransactio D s
ns = Warehouse.StockIte Foreign key constraint referencing
ms.StockItemID StockItems.StockItemID

Khóa độc nhất (unique key)


Columns Name/Description
PackageTypeID PK_Warehouse_PackageTypes
(Khóa chính)
PackageTypeName UQ_Warehouse_PackageTypes_PackageTypeName
(Khóa độc nhất)

1.3.10. Bảng: Warehouse.PackageTypes


X Name Data N Decription
PackageTypeID int Khóa chính loại gói.
(Cột nhận dạng / tự động tăng)
PackageTypeName nvarchar(50) Tên loại gói
LastEditedBy int Lần thay đổi cuối
ValidFrom datetime2(7) Có hiệu lực từ ngày
ValidTo datetime2(7) Có hiệu lực đến ngày
Liên kết:
Table Join Title/Name/Description
Warehouse.PackageT FK_Warehouse_PackageTypes_Applicat
Application.Pe ypes.LastEditedBy = ion_People
ople Application.People.Per Tham chiếu ràng buộc khóa ngoại
sonID People.PersonID
Sales.InvoiceLines.Pac FK_Sales_InvoiceLines_PackageTypeID
Sales.InvoiceLi kageTypeID = _Warehouse_PackageTypes
nes Warehouse.PackageT Tham chiếu ràng buộc khóa ngoại
ypes.PackageTypeID PackageTypes.PackageTypeID
Sales.OrderLines.Packa FK_Sales_OrderLines_PackageTypeID_
Sales.OrderLin geTypeID = Warehouse_PackageTypes
es Warehouse.PackageT Tham chiếu ràng buộc khóa ngoại
ypes.PackageTypeID PackageTypes.PackageTypeID
FK_Purchasing_PurchaseOrderLines_Pa
Purchasing.Pur Purchasing.PurchaseOr ckageTypeID_Warehouse_PackageType
chaseOrderLin derLines.PackageTypeI s
es D Tham chiếu ràng buộc khóa ngoại
PackageTypes.PackageTypeID

25
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

= Warehouse.Package
Types.PackageTypeID

Warehouse.StockItems. FK_Warehouse_StockItems_OuterPacka
Warehouse.Sto OuterPackageID = geID_Warehouse_PackageTypes
ckItems Warehouse.PackageT Tham chiếu ràng buộc khóa ngoại
ypes.PackageTypeID PackageTypes.PackageTypeID
Warehouse.StockItems. FK_Warehouse_StockItems_UnitPackag
Warehouse.Sto UnitPackageID = eID_Warehouse_PackageTypes
ckItems Warehouse.PackageT Tham chiếu ràng buộc khóa ngoại
ypes.PackageTypeID PackageTypes.PackageTypeID

Khóa độc nhất (unique key)


Columns Name/Description
StockItemID PK_Warehouse_StockItems
(Khóa chính)
StockItemName UQ_Warehouse_StockItems_StockItemName (Khóa
độc nhất)

1.3.11. Bảng: Warehouse.Colors


X Name Data N Decription
ColorID int Khóa chính màu
(Cột nhận dạng / tự động tăng)
ColorName nvarchar(20) Tên màu
LastEditedBy int Lần thay đổi cuối
ValidFrom datetime2(7) Có hiệu lực từ ngày
ValidTo datetime2(7) Có hiệu lực đến ngày

Liên kết:
Table Join Title/Name/Description
Warehouse.Colors.La FK_Warehouse_Colors_Application_Pe
Application.Pe stEditedBy = ople
ople Application.People.Per Tham chiếu ràng buộc khóa ngoại
sonID People.PersonID
Warehouse.StockItems. FK_Warehouse_StockItems_ColorID_
Warehouse.Sto ColorID = Warehouse_Colors
ckItems Warehouse.Colors.Co Tham chiếu ràng buộc khóa ngoại
lorID Colors.ColorID

Khóa độc nhất (unique key)


Columns Name/Description

26
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

ColorID PK_Warehouse_Colors
(Khóa chính)
ColorName UQ_Warehouse_Colors_ColorName
(Khóa độc nhất)

2 Mô tả database database warehouse


2.1. Diagram database warehouse

Hình 2. Sơ đồ Diagram DW

2.2. Bảng: DimCustomers


X Name Data N Decription
CustomerKey int Khóa chính khách hàng
(Khóa thay thế / tự động tăng)
CustomerID int Mã số khách hàng
CustomerName nvarchar(200) Tên khách hàng

27
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

CustomerCategoryN nvarchar(200) Tên thể loại khách hàng


ame
DeliveryCity nvarchar(200) Địa chỉ thành phố giao hàng
DeliveryStateProvic nvarchar(200) Địa chỉ bang/tỉnh giao hàng
e
DeliveryCountryReg nvarchar(200) Đỉa chỉ đất nước
ion

2.3. Bảng: DimDates


X Name Data N Decription
CalendarDateKey int Khóa chính ngày
(Khóa thay thế)
CalendarDateName nvarchar(100) Thứ/Ngày/Tháng/Năm
CalendarYearMont nvarchar(100) Tháng
hName
CalendarYearQuart nvarchar(100) Quý
erName
CalendarYearName nvarchar(100) Năm
CalendarDate Date Ngày/Tháng/Năm

2.4. Bảng: DimSalesPersons


X Name Data N Decription
SalesPersonKey int Khóa chính người bán hàng
(Khóa thay thế)
SalesPersonID int Mã số người bán hàng
SalesPersonName nvarchar(100) Tên người bán hàng

2.5. Bảng: DimStockItems


X Name Data N Decription
StockItemKey int Khóa chính sản phẩm
(Khóa thay thế)
StockItemID int Mã số sản phẩm
StockItemName nvarchar(100) Tên sản phẩm
StockItemColor nvarchar(100) Màu sản phẩm
StockItemSize nvarchar(100) Kích cỡ sản phẩm
UnitPackageName nvarchar(100) Mã số loại sản phẩm

2.6. Bảng: FactSale


28
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

X Name Data N Decription


InvoiceID int Khóa chính hóa đơn
(Khóa thay thế)
InvoiceLineID int Khóa chính hóa đơn
InvoiceDateKey int Ngày đặt hàng
StockItemKey int Khóa thay thế của bảng
DimStockItem
CustomerKey int Khóa thay thế của bảng
DimCustomers
SalesPersonKey int Khóa thay thế của bảng
DimSalesPerson
Quantity smallint Số lượng
UnitPrice money Giá bán 1 sản phẩm
TaxRate money Mức thuế
TaxAmount money số tiền thuế
LineProfit money Tổng tiền của một dòng. Được tính:
Đơn giá * (1 – giá trị giảm) * số
lượng đặt hàng.

ExtendedPrice money Giá đã cộng thuế

Liên kết:
Table Join Title/Name/Description
FactSale. FK_FactSale_DimCustomer_CustomerKey
CustomerKey = Tham chiếu ràng buộc khóa ngoại
DimCustomers
DimCustomer. DimCustomers.CustomerKey.
CustomerKey
FactSale. FK_FactSale_DimCustomer_CustomerKey
ProductKey = Tham chiếu ràng buộc khóa ngoại
DimProducts
DimCustomer. DimProducts.ProductKey.
ProductKey
FactSale. FK_FactSale_DimDates _OrderDateKey _
OrderDateKey = CalendarDateKey
DimDates DimDates. Tham chiếu ràng buộc khóa ngoại
CalendarDateKey DimDates.CalendarDateKey cho
OrderDateKey.
FactSale. FK_FactSale_DimDates
ShipDateKey = _ShipDateKey_CalendarDateKey
DimDates DimDates. Tham chiếu ràng buộc khóa ngoại
CalendarDateKey DimDates.CalendarDateKey cho
ShipDateKey.

29
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

3 SSIS database warehouse


3.1. Mô hình SSIS

Bước 1: Reset database


Bước 2: Load Dimesion Tables
Bước 3: Create Foreign Keys
Bước 4: Load Fact Table
3.1.1. Reset Database

30
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

o Chỉnh kết nối của Connection và SQL Statement


▪ Connection: đến database SQL
▪ SQL Statement: Câu lệnh khởi tạo Database và các
bảng DimCustomer, DimDate, DimStockItems,
FactSales

31
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4 Sequence Container: Load Dimension Tables

4.1. Load DimCustomer

4.1.1. ADO NET Source: Customer Data Source

32
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

33
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.1.2. Sort Transformation Editor: Customer Sort

34
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Khóa CustomerCategoryID là khóa kết


4.1.3. ADO NET Source: Customer Category Source

35
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.1.4. Sort Transformation Editor: Customer Sort

36
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Có CustomerCategoryID là khóa kết


4.1.5. Merge Join: Container Category và Customer

37
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Các cột dữ liệu lấy:


o Customer.CustomerID (output: CustomerID)
o Customer.CustomerName (output: CustomerName)
o CustomerCategory.CustomerCategoryName
(CustomerCategoryName)
o Customer.DeliveryCityID (output: DeliveryCityID)
4.1.6. Sort Transformation Editor: Customer & Category Sort

38
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn DeliveryCityID làm khóa kết


4.1.7. ADO NET Destination: Cities Source Data

39
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.1.8. Sort Transformation Editor: Cities Sort

40
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Lấy CityID làm khóa kết

4.1.9. Merge Join: Category & Customer và Cities

41
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Các cột dữ liệu lấy:


o Customer&Category.CustomerID(output: CustomerID)
o Customer&Category.CustomerName(output:
CustomerName)
o Customer&Category.CustomerCategoryName(output:
CustomerCategoryName)
o Cities.CityName(output: CityName)
o Cities.StateProviceID(output: StateProviceID)
4.1.10. Sort Transformation Editor: Customer và City
42
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Có khóa StateProvinceID là khóa kết


4.1.11. ADO NET Soure: StateProvinceData

43
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.1.12. Sort Transformation Editor: StateProvinces Sort


44
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Có khóa StateProvinceID là khóa kết


4.1.13. Merge Join: Category & Customer và Cities

45
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Các cột dữ liệu lấy:


o Customer&City.CustomerID(output: CustomerID)
o Customer&City.CustomerName(output: CustomerName)
o Customer&City.CustomerCategoryName(output:
CustomerCategoryName
o Customer&City.DeliveryCity(output: DeliveryCity)
o StateProvinces.StateProvincesName(output:
StateProvincesName)
o StateProvinces.CountryID(output: CountryID)
46
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.1.14. Sort Transformation Editor: Customer & City &


StateProvince Sort

- Chọn CountryID là khóa kết


4.1.15. ADO NET Source: Product & ProductCatogery Data

47
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.1.16. Sort Transformation Editor: StateProvinces Sort

48
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn CountryID là khóa kết


4.1.17. Merge Join: Customer & City & StateProvince và
Country

49
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Các cột dữ liệu lấy:


o Customer&City&StateProvince.CustomerID(output:
CustomerID)
o Customer&City&StateProvince.CustomerName(output:
CustomerName)
o Customer&City&StateProvince.CustomerCategoryName
(output: CustomerCategoryName

50
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

o Customer&City&StateProvince.DeliveryCity(output:
DeliveryCity)
o Customer&City&StateProvinces.DeliveryStateProvice(ou
tput: DeliveryStateProvice)
o Country.CountryName(output: CountryName)
4.1.18. Sort Transformation Editor: Customer & City &
StateProvince & Country Sort

- Chọn CustomerID là khóa kết


4.1.19. ADO NET Destination: Load DimCustomers

51
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

52
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.2. Load DimStockItems


4.2.1. ADO NET Source: StockItems Data

53
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.2.2. Sort Transformation Edit: StockItems Column

54
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn khóa UnitPackageID là khóa kết


4.2.3. ADO NET Source: PackageTypes Data

55
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.2.4. Sort Transformation Edit: PackageTypes Sort

- Chọn PackageTypeID là khóa kết


4.2.5. Merge Joins: StockItems & PackageTypes

56
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Các cột dữ liệu lấy:


o StockItems.StockItemID(output: StockItemID)
o StockItems. StockItemName(output: StockItemName)
o StockItems.ColorID(output: ColorID)
o PackageTypes. PackageTypesName(output:
PackageTypesName)
o StockItems.Size(output: Size)
4.2.6. Derived Column Tranformation: Transform Color
Column

57
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.2.7. Sort Transformation Edit: StockItem & UnitPackage


Sort

58
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn TransformColorID là khóa kết


4.2.8. ADO NET Source: Colors Data

59
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.2.9. Sort Transformation Edit: Colors Sort

60
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn ColorID là khóa kết


4.2.10. Merge join: StockItem & UnitPackage và Colors

61
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Các cột dữ liệu lấy:


o StockItems&UnitPackage.StockItemID(output:
StockItemID)
o StockItems&UnitPackage. StockItemName(output:
StockItemName)
o StockItems&UnitPackage.UnitPackageName(output:
UnitPackageName)
o StockItems&UnitPackage. Size(output: Size)
o Colors.ColorName(output: ColorName)
4.2.11. Derived Column Tranformation: Transform
ColorName, Size Column

62
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.2.12. Sort Transformation Edit:Sort

- Chọn StockItemID là khóa


4.2.13. ADO NET Destination: DimStockItems

63
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

64
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.3. DimSalesPersons

4.3.1. ADO NET Source: People Data


65
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.3.2. Conditional Split Transformation: Conditional Split

66
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Kiểm tra null


4.3.3. Sort Transformation: Sort

67
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn column:
o PersonID
4.3.4. ADO NET Destination: Load DimSalesPersons

68
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.4. Load DimDate


4.4.1. Câu lệnh SQL:

69
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

-- Đổ dữ liệu vào bảng DimDates


Declare @StartDate date;
Declare @EndDate date;

-- Lấy ra ngày bắt đầu của năm nhỏ nhất trong OrderDate
Select @StartDate = '01-01-' + Cast(Year(Min(InvoiceDate)) as nvarchar(50))
From WideWorldImporters.Sales.Invoices;
-- Lấy ra ngày cuối cùng của năm lớn nhất trong OrderDate
Select @EndDate = '12-31-' + Cast(Year(Max(InvoiceDate)) as nvarchar(50))
From WideWorldImporters.Sales.Invoices;

-- Gán 1 biến làm ngày bắt đầu


Declare @cur_Date datetime = @StartDate;

While @cur_Date <= @EndDate


Begin
Insert Into DimDates
( CalendarDateKey
, CalendarDateName
, CalendarYearMonthName
, CalendarYearQuarterName
, CalendarYearName
, CalendarDate
)
Values (
Convert(nvarchar(50), @cur_Date, 112) -- CalendarDateKey
, DateName( weekday, @cur_Date ) + ', ' + Convert(nvarchar(50),
@cur_Date, 105) -- CalendarDateName
, DateName( month, @cur_Date ) -- CalendarYearMonthName
, 'Q' + DateName( quarter, @cur_Date ) -- CalendarYearQuarterName
--, Cast( Year( @cur_Date) as nVarchar(50) ) -- CalendarYearName
, DATENAME(YEAR, @cur_Date) ---- CalendarYearName
, Convert(date, @cur_Date) -- CalendarDate
);
-- Tăng thêm 1 ngàys
Set @cur_Date = DateAdd(d, 1, @cur_Date);
End

70
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.4.2. Sequence Container: Create Foreign Keys


- Excute SQL Task: Create Foreign Keys

71
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.5. FactSales

72
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.5.1. ADO NET Destination: Invoice Source Data

73
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.5.2. ADO NET Destination: InvoiceLine Source

74
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

75
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.5.3. Sort Transformation: Invoice Sort

76
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn column: InvoiceID


4.5.4. Sort Transformation: InvoiceLine Sort

77
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn column: InvoiceID


4.5.5. Merge Joins: Invoice và InvoiceLine

78
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Invoice.InvoiceID (output: InvoiceID)


- InvoiceLine.InvoiceLineID (output: InvoiceLineID)
- Invoice.CustomerID (output: CustomerID)
- InvoiceLine.StockItemID (output: StockItemID)
- Invoice.SalespersonPersonID (output: SalespersonPersonID)
- InvoiceLine.Quantity (output: Quantity)
- InvoiceLine.UnitPrice (output: UnitPrice)
- InvoiceLine.TaxRate (output: TaxRate)
- InvoiceLine.TaxAmount (output: TaxAmount)
- InvoiceLine.LineProfit (output: LineProfit)
79
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- InvoiceLine.ExtendedPrice (output: ExtendedPrice)


- Invoice.InvoiceDate (output: InvoiceDate)
4.5.6. ADO NET Destination: DimStockItems Data

80
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.5.7. Sort Transformation: DimStockItem Sort

81
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn column: StockItemID


4.5.8. SortTransformation: Sale Sort

82
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn column: StockItemID


4.5.9. Merge Joins: Sale và DimStockItem

83
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Sales.InvoiceID (output: InvoiceID)


- Sales.InvoiceLineID (output: InvoiceLineID)
- Sales.CustomerID (output: CustomerID)
- Sales.SalespersonPersonID (output: SalespersonPersonID)
- Sales.Quantity (output: Quantity)
- Sales.UnitPrice (output: UnitPrice)
- Sales.TaxRate (output: TaxRate)
- Sales.TaxAmount (output: TaxAmount)
84
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Sales.LineProfit (output: LineProfit)


- Sales.ExtendedPrice (output: ExtendedPrice)
- Sales.InvoiceDate (output: InvoiceDate)
- DimStockItems.StockItemKey (output: StockItemKey)
4.5.10. ADO NET Destination: DimSalesPersons Source

85
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.5.11. SortTransformation: DimSalesPerson Sort

86
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn column: SalesPersonID


4.5.12. SortTransformation: Sales & StockItem Sort

- Chọn column: SalespersonPersonID


4.5.13. Merge Joins: Sales & StockItem và DimSalesPerson

87
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Sales&StockItem.InvoiceID (output: InvoiceID)


- Sales&StockItem.InvoiceLineID (output: InvoiceLineID)
- Sales&StockItem.CustomerID (output: CustomerID)
- Sales&StockItem.Quantity (output: Quantity)
- Sales&StockItem.UnitPrice (output: UnitPrice)
- Sales&StockItem.TaxRate (output: TaxRate)
- Sales&StockItem.TaxAmount (output: TaxAmount)
- Sales&StockItem.LineProfit (output: LineProfit)
- Sales&StockItem.ExtendedPrice (output: ExtendedPrice)
- Sales&StockItem.InvoiceDate (output: InvoiceDate)
88
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Sales&StockItem.StockItemKey (output: StockItemKey)


- DimSalesPerson.SalesPersonKey (output: SalesPersonKey)
4.5.14. ADO NET Destination: DimCustomer Source

89
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.5.15. SortTransformation: DimCustomers Sort

90
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn column: CustomerID


4.5.16. SortTransformation: Sales & StockItems &
SalesPerson Sort

91
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn column: CustomerID


4.5.17. Merge Joins: Sales & StockItems & SalesPerson Sort và
DimCustomers

92
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Sales&StockItems&SalesPerson. InvoiceID (output: InvoiceID)


- Sales&StockItems&SalesPerson. InvoiceLineID (output:
InvoiceLineID)
- Sales&StockItems&SalesPerson. Quantity (output: Quantity)
- Sales&StockItems&SalesPerson. UnitPrice (output: UnitPrice)
- Sales&StockItems&SalesPerson. TaxRate (output: TaxRate)
- Sales&StockItems&SalesPerson. TaxAmount (output:
TaxAmount)
- Sales&StockItems&SalesPerson. LineProfit (output: LineProfit)

93
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Sales&StockItems&SalesPerson. ExtendedPrice (output:


ExtendedPrice)
- Sales&StockItems&SalesPerson. InvoiceDate (output:
InvoiceDate)
- Sales&StockItems&SalesPerson. StockItemKey (output:
StockItemKey)
- Sales&StockItems&SalesPerson. SalesPersonKey (output:
SalesPersonKey)
- DimCustomer. CustomerKey (output: CustomerKey)
4.5.18. ADO NET Destination: DimDates Data

94
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.5.19. SortTransformation: DimDates Sort

95
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn column: CalendarDate


4.5.20. SortTransformation: Sales & StockItems &
SalesPerson & Customer Sort

96
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn column: InvoiceDate


4.5.21. Merge Joins: Sales & StockItems & SalesPerson &
Customer và DimDates

97
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Sales&StockItems&SalesPerson&Customer. InvoiceID (output:


InvoiceID)
- Sales&StockItems&SalesPerson&Customer. InvoiceLineID
(output: InvoiceLineID)
- Sales&StockItems&SalesPerson&Customer. Quantity (output:
Quantity)
- Sales&StockItems&SalesPerson&Customer. UnitPrice (output:
UnitPrice)
- Sales&StockItems&SalesPerson&Customer. TaxRate (output:
TaxRate)

98
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Sales&StockItems&SalesPerson&Customer. TaxAmount
(output: TaxAmount)
- Sales&StockItems&SalesPerson&Customer. LineProfit (output:
LineProfit)
- Sales&StockItems&SalesPerson&Customer. InvoiceDate
(output: InvoiceDate)
- Sales&StockItems&SalesPerson&Customer. StockItemKey
(output: StockItemKey)
- Sales&StockItems&SalesPerson&Customer. SalesPersonKey
(output: SalesPersonKey)
- Sales&StockItems&SalesPerson&Customer. CustomerKey
(output: CustomerKey)
- DimDates. InvoiceDateKey(output: InvoiceDateKey)
4.5.22. SortTransformation: Sort

- Chọn column: InvoiceID


4.5.23. ADO NET Destination: Load FactSales

99
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

100
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

4.6. Chạy chương trình

101
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

5 SSAS
5.1. Tạo project mới
- Mở Visual Studios
- Chọn File -> New -> Project
- Chọn Analysis Services Multidimensional and Data Mining Project

102
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

5.2. Connect đến Data Sources


- Chọn Data Sources

- Chọn Create a data source based on an existing on new connection


- Click New

103
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn Use the service account

104
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Đổi tên dữ liệu bạn muốn ở Data source name

- Chọn Finish để hoàn tất


5.3. Điều chỉnh lại phân quyền của SQL Databasse
- Mở SQL Server và kết nối đến account chứa database
- Chọn Security -> Login -> NT AUTHORITY/NETWORK SERVICE

105
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Click chuột phải, chọn Properties

- Chọn User Mapping


- Chọn Database cần phân quyền (DW_WideWordImporters)
- Chọn db datareader
106
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

5.4. Tạo Data Source View


- Quay lại Visual Studios
- Chọn Data Source Views
- Chọn New Data Source View

- Kết nối với database đã kết nối trước

107
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn bảng Fact (FactSales)


- Click “>”

- Click Add Related Tables

108
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Đổi tên và Finish

5.5. Tạo Dimessions


- Chọn Dimessions
- Chọn New Dimessions

109
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

5.5.1. DimDate
- Chọn Use an existing table

- Chọn table muốn add (DimDates) trong Main table

110
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn những thuộc tính muốn add và đổi tên theo ý muốn

- Đổi tên và Finish

111
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chỉnh lại kiểu dữ liệu của Calendar Date


- Chọn trong Properties

- Trong Basic, chọn Type, chọn Date -> Calendar-> Dates

112
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Tương tự đổi Type của Calendar thành Months

- Tương tự đổi Type của Calendar thành Quarters

113
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Tương tự đổi Type của Calendar thành Years

5.6. Tạo Cubes


- Chọn Cubes
- Chọn New Cubes

114
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn Use an existing table

- Chọn table muốn add (FaleSales) trong Measure group tables

115
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn những thuộc tính muốn add và đổi tên theo ý muốn

116
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Đổi tên và Finish

117
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Sau đó các bảng Dim sẽ được tạo một cách tự động


- Chọn Deploy để chạy

5.7. Chỉnh sửa lại các thuộc tính của các bảng Dim
5.7.1. DimSalesPerson
- Sửa tên của bảng trong Properties thuộc tính Name
118
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Ở đây thuộc tính NameColumn là none nên dữ liệu sẽ được sắp xếp theo
mặc định là khóa chính của bảng

119
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Để thay đổi qua cột muốn hiện lên khi sắp xếp ta chọn cột cho thuộc tính
NameColumn, ở đây mình chọn cột SalesPersonName

120
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Sau đó deloy để hoàn tất


- Chuyển sang tab Browser và ấn reconnect để kiểm tra

121
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

5.7.2. DimCustomers
- Tương tự DimSalesPerson
- Di chuyển các thuộc tính đưa vào sắp xếp

- Đổi tên trường Name trong Properties


o Customer Category Name -> Customer Category
o Delivery City -> City
o Delivery Country Region -> Country Region
o Delivery State Province -> State Province

122
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Tạo các độ đo theo thứ tự


o Country Region -> State Provice -> City -> Customer Category ->
Customer

- Chỉnh lại thuộc tính Relationship Type là Rigid để ko sửa

123
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Deploy và t có kết quả

5.7.3. Dim Stock Items


- Tương tự DimSalesPerson
- Di chuyển các thuộc tính đưa vào sắp xếp

124
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Đổi tên trường Name trong Properties


o Stock Item Color -> Color
o Stock Item Key -> Stock Item
o Stock Item Size -> Item Size
o Unit Package Name -> Unit Package

125
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Tạo các độ đo theo thứ tự


o Country Region -> State Provice -> City -> Customer Category ->
Customer

- Chỉnh lại thuộc tính Relationship Type là Rigid để ko sửa

126
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Deploy và t có kết quả

5.7.4. Dim Date


- Tương tự DimSalesPerson
- Di chuyển các thuộc tính đưa vào sắp xếp

127
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Tạo các độ đo theo thứ tự


o Calendar Year -> Calendar Quanter -> Calendar Month -> Calendar
Date

- Chỉnh lại thuộc tính Relationship Type là Rigid để ko sửa

128
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Thêm Key Column trong Properties của Calendar Month là


CalendarYearName

129
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Thêm Key Column trong Properties của Calendar Quarter là


CalendarYearName

- Tại file .dsv t thêm New Named Calculation cho bảng DimDate

130
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Explore Data để kiểm tra

131
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chỉnh lại Name Column cho Calendar Month trong Properties

132
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chỉnh lại Name Column cho Calendar Quarter trong Properties

- Chỉnh lại Name Column cho Calendar Date trong Properties

133
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Deploy và t có kết quả

134
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

5.8. Điều chỉnh Cubes (Sales.Cubes)


- Điều chỉnh trong tab Measure

- tab Browser chọn biểu tượng trên thanh tool bar có hình Excel

135
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Để kiểm tra việc phân tích ở Excel và VS có giống nhau hay ko


- Ở Excel
o Ta chọn thuộc tính độ đo trong PrivotTable Fields

o Chọn vào dữ liệu muốn đo

136
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

o Kéo thả vào trong tab Row để tạo Dòng muốn đo

o Kéo thả vào trong tab Column để tạo Cột muốn đo

137
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

o Từ đó t có bảng dữ liệu như đây

- Chỉnh các kiểu dữ liệu lại ở tab Format String trong Properties
o Với Quantity chỉnh thành #,# (có ngăn cách dấu phẩy ở đơn vị)
o Với Unit Price, Tax Amount, Line Profit, Extended Price chỉnh
thành Currency

138
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

o Với Tax Rate chỉnh thành Percent

139
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Deploy và có kết quả

5.9. Tạo thêm độ đo Distinct Count


- Tab Measure ta chọn Sale -> New Measure

140
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn Distinct Count ở Usage và Chọn cột dữ liệu (InvoiceID)

6 Ngôn ngữ MDX:


6.1. Câu 1:
- Mô tả bằng ngôn ngữ tự nhiên: Truy vấn ra những sản phẩm được bán có tổng giá
[Extended Price] trừ đi lợi nhuận [Line Profit] lớn hơn 2000000 và sắp xếp giảm dần theo
[Extended Price] - [Line Profit].

Hình 1. Câu truy vấn MDX của câu 1.

141
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 2. Kết quả truy vấn của Hình 1 thực hiện trên SSMS

Hình 3 Tạo Name Sets tương ứng với câu truy vấn của Hình 1

142
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 4. Kết quả truy vấn của Hình 1 trên VS Studio

Hình 5. Kết quả truy vấn của Hình 1 trên Pivot Excel

6.2. Câu 2:
- Mô tả bằng ngôn ngữ tự nhiên: Truy vấn ra những tiểu bang có chữ cái đầu là “C” và sắp
xếp tăng dần theo tổng giá [Extended Price].

143
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 6. Câu truy vấn MDX của câu 2

Hình 7. Kết quả truy vấn của Hình 6 trên SSMS

144
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 8. Tạo Name Sets của câu truy vấn Hình 6

Hình 9. Kết quả truy vấn của Hình 6 trên VS Studio

145
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 10. Kết quả truy vấn của Hình 6 trên Pivot Excel

6.3. Câu 3:
- Mô tả bằng ngôn ngữ tự nhiên: Trong mỗi quý năm 2016 truy vấn ra 5 thành phố có
nhiều hoá đơn mua hàng nhất.

Hình 11. Câu truy vấn MDX của câu 3

146
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 12. Kết quả truy vấn của Hình 11 trên SSMS

Hình 13. Tạo Name Sets của câu truy vấn Hình 11

147
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 14. Kết quả truy vấn của Hình 11 trên VS Studio

Hình 15. Kết quả truy vấn của Hình 11 trên Pivot Excel

6.4. Câu 4:
- Mô tả bằng ngôn ngữ tự nhiên: Trong bộ dữ liệu gồm các tiểu bang Alabama, California,
Hawaii, Iowa. Truy vấn drill down tiểu bang Iowa và sắp xếp tất cả theo thứ tự giảm dần
của giá chưa tính thuế [Unit Price] trong năm 2016.

148
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 16. Câu truy vấn MDX của câu 4

Hình 17. Kết quả truy vấn của Hình 16 trên SSMS

149
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 18. Tạo Name Sets của câu truy vấn Hình 16

Hình 19. Kết quả truy vấn của Hình 16 trên VS Studio

150
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 20. Kết quả truy vấn của Hình 16 trên Pivot Excel

6.5. Câu 5:
- Mô tả bằng ngôn ngữ tự nhiên: Trong mỗi tiểu bang, truy vấn ra 5 thành phố trả số tiền
thuế [Tax Amount] khi mua những sản phẩm có loại đóng gói là [Packet] theo thứ tự
giảm dần.

Hình 21. Câu truy vấn MDX của Câu 5.

151
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 22. Kết quả truy vấn của Hình 21 trên SSMS

Hình 23. Tạo Name Sets của câu truy vấn Hình 21

152
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 24. Kết quả truy vấn của Hình 21 trên VS Studio

Hình 25. Kết quả truy vấn của Hình 21 trên Pivot Excel

6.6. Câu 6:
- Mô tả bằng ngôn ngữ tự nhiên: Truy vấn ra những khách hàng vừa mua sản phẩm [Dim
Stock Items].[Stock Item].&[1] và vừa mua sản phẩm [Dim Stock Items].[Stock
Item].&[3], và mua mỗi sản phẩm từ 30 cái trở lên.

153
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 26. Câu truy vấn MDX của Câu 6

Hình 27. Kết quả truy vấn của Hình 26 trên SSMS

154
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 28. Tạo Name Sets của câu truy vấn Hình 26

Hình 29. Kết quả truy vấn của Hình 26 trên VS Studio

155
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 30. Kết quả truy vấn của Hình 26 trên Pivot Excel

6.7. Câu 7:
- Mô tả bằng ngôn ngữ tự nhiên: Trong tháng 1, 2 ,3 của quý 1 của mỗi năm truy vấn ra 5
tiểu bang có số hoá đơn [InvoiceDistinct Count] giảm dần.

Hình 31. Câu truy vấn MDX của Câu 7

156
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 32. Kết quả truy vấn của Hình 31 trên SSMS

Hình 33. Tạo Name Sets của câu truy vấn Hình 31

157
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 34. Kết quả truy vấn của Hình 31 trên VS Studio

Hình 35. Kết quả truy vấn Hình 31 trên Pivot Excel

6.8. Câu 8:
- Mô tả bằng ngôn ngữ tự nhiên: Sử dụng member [Extend Price Prev] là tổng giá của quý
trước, [Extend Price Diff] là tổng giá của quý hiện tại [Extended Price] trừ đi tổng giá của
quý trước [Extend Price Prev]. Truy vấn tổng giá của quý hiện tại, tổng giá của quý trước
đó và so sánh tổng giá của 2 quý này.

158
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 36. Câu truy vấn MDX của Câu 8

Hình 37. Kết quả truy vấn của Hình 36 trên SSMS

159
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 38 Tạo Calculated Member [Extend Price Prev] của truy vấn Hình 36

Hình 39. Tạo Calculated Member [Extend Price Diff] của truy vấn Hình 36

160
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 40 Kết quả truy vấn của Hình 36 trên VS Studio

Hình 41. Kết quả truy vấn của Hình 36 trên Pivot Excel

6.9. Câu 9:
- Mô tả bằng ngôn ngữ tự nhiên: Truy vấn ra những tiểu bang vừa mua sản phẩm [Top
Quantity Item 2015] và vừa mua sản phẩm [Top Quantity Item 2016].
- Với Set [Top Quantity Item 2015] là sản phẩm được bán ra nhiều nhất trong năm 2015.
- Với Set [Top Quantity Item 2016] là sản phẩm được bán ra nhiều nhất trong năm 2016.

161
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Member [Quantity of Top 1 Quanity Item in 2015] là số lượng đã mua sản phẩm [Top
Quantity Item 2015] trong năm 2015.
- Member [Quantity of Top 1 Quanity Item in 2016] là số lượng đã mua sản phẩm [Top
Quantity Item 2016] trong năm 2016.

Hình 42. Câu truy vấn MDX của Câu 9

Hình 43. Kết quả truy vấn của Hình 42 trên SSMS

162
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 44 Tạo Name Sets [Top Quantity Item 2015]

Hình 45. Tạo Name Sets [Top Quantity Item 2016]

163
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 46. Tạo Calculated Member [Quantity of Top 1 Quanity Item in 2015]

Hình 47. Tạo Calculated Member [Quantity of Top 1 Quanity Item in 2016]

164
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 48. Tạo Names Sets của câu truy vấn Hình 42

Hình 49. Kết quả truy vấn của Hình 42 trên VS Studio

165
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 50. Kết quả truy vấn của Hình 42 trên Pivot Excel

6.10. Câu 10:


- Mô tả bằng ngôn ngữ tự nhiên: Truy vấn ra những khách hàng đã mua tất cả sản phẩm
trong [Top 25 Percent Extended Price Item in 2014].
- Với Set [Top 25 Percent Extended Price Item in 2014] là top những sản phẩm có tổng
[Extended Price] chiếm 25% tổng [Extended Price] của tất cả các sản phẩm trong năm
2014.
- Member [Extended Price of Each Item in Top 25 Percent Extended Price Item in 2014] là
[Extended Price] của mỗi sản phẩm trong set [Top 25 Percent Extended Price Item in
2014] trong năm 2014.

166
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 51. Câu truy vấn MDX của câu 10

Hình 52. Kết quả truy vấn của Hình 51.

167
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 53. Tạo Name Set [Top 25 Percent Extended Price Item in 2014]

Hình 54. Tạo Calculated Member [Extended Price of Each Item in Top 25 Percent Extended Price Item in 2014]

168
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 55. Tạo Name Set của truy vấn Hình 51

Hình 56. Kết quả truy vấn của Hình 51 trên VS Studio

169
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

Hình 57. Kết quả truy vấn của Hình 51 trên Pivot Excel

7 SSRS
7.1. Tạo project SSRS và thêm data source, dataset
• Tạo project SSRS trên Visual Sudio

170
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

• Thêm datasource cho report

171
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

• Tạo dataset từ datasourse vừa tạo

172
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

7.2. Tạo report bảng với Grouping và Totals


• Thêm bảng vào report

• Kéo thả các thuộc tính mà đã truy vấn trên dataset vào bảng.

173
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

• Kéo thuộc tính State Province và Stock Item vào Row Groups
• State Province -> Stock Item -> Details

• Xem Preview, kiểm tra dữ liệu đã đúng hay chưa

174
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

• Xoá 2 cột State Province và StockItem khi chưa grouping

• Chuột phải vào cột Quantity chọn add totals


• Đặt tên cho totals đó là Stock Item Total

175
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

• Xem dữ liệu sau khi them Stock Item Total

• Chuột phải vào cột Stock Item Add Total -> chọn After, đặt tên cho group là State
Province Total

176
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

• Tương tự them vào Grand Total bằng cách chuột phải vào cột State Province chọn
add total -> after

177
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

• Xem dữ liệu sau khi thêm grouping và total

7.3. Tạo Report thứ 2


• Tương tự như ở report thứ nhất, ta cũng thêm datasource và dataset, ở bước chọn
dataset ta sẽ query dữ liệu Liệt kê tổng Extended Price và Line Profit theo tiểu bảng,
người bán hàng và theo từng năm.

178
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

• Tiếp theo ta sẽ thêm bảng và kéo thả các dữ liệu cần thiết và thêm grouping và total

• Xem preview và kiểm tra dữ liệu đã hiển thị đúng theo grouping và total hay chưa

179
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

180
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

7.4. Deploy project SSRS và đưa report lên server


• Chuột phải vào tên project chọn Deploy

• Sau khi deploy thành công thì nhập vào đường link để mở report trực tiếp trên server

181
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

8 Data Mining
8.1. Mô tả về dataset dùng để mining.
- Tên dataset : Cardiovascular Disease (Dữ liệu về bệnh tim mạch)
- Link: https://www.kaggle.com/sulianova/cardiovascular-disease-dataset

182
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Dữ liệu gồm 70000 dòng và có 12 cột thuộc tính:


o Age (days): tuổi được tính theo ngày.
o Height: chiều cao (cm).
o Weight: cân nặng (kg).
o Gender: giới tính gồm Male (Nam), Female (Nữ).
o Ap_hi: chỉ số huyết áp tâm thu.
o Ap_lo: chỉ số huyết áp tâm trương.
o Cholesterol: Cholesterol gồm normal (bình thường), above normal (cao), well
above normal (rất cao).
o Glucose: lượng đường trong máu gồm normal (bình thường), above normal
(cao), well above normal (rất cao).
o Smoking: có hút thuốc hay không gồm 1 (có), 0 (không).
o Alcohol intake: có uống rượu hay không gồm 1 (có), 0 (không).
o Physical activity(active): có tập thể dục hay không 1 (có), 0 (không).
o Cardio: có bị bênh tim mạch hay không 1 (có), 0 (không).
8.2. Đổ dữ liệu vào SQL Server bằng công cụ SSIS
- Tạo bảng cho dataset bằng sql server:

183
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Đổ dữ liệu từ file Excel vào SQL Server:

- Excel Source kết nối tới file Excel chứa dataset ban đầu

184
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Conditinal Split loại bỏ dữ liệu null

- Derived Column chuyển Age (days) sang Age (years).

185
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- ADO NET Destination đổ dữ liệu vào bảng trong sql server

8.3. Data mining bằng công cụ SSAS trên Visual Studio


- Add Datasource với database đã tạo ở phần trên

186
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Add DataSource View với table Cardio_Train

- Tạo Mining Structures

187
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn thuật toán để mining là Microsoft Decision Trees (Thuật toán cây
quyết định).

- Chọn Cardio_Train làm case để chạy thuật toán mining

188
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn thuộc tính key là ID, và thuộc tính Predict (dự đoán) là Cardio (tình
trạng có bị bệnh tim hay không).

- Xem các thuộc tính được suggest

189
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Chọn các thuộc tính để làm input:


o Active
o Age
o Alco
o Ap_hi
o Ap_lo
o Cholesterol
o Gender
o Gluc
o Height
o Smoke
o Weight

190
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Detect các trường dữ liệu

- Chọn 30% bộ dữ liệu để test và 70% dữ liệu để train, số lượng case tối đa để
test là 1000.

191
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Đặt tên cho model mining là Cardio Train Tree.

- Chỉnh sửa HoldoutSeed thành 12.

192
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Thêm thuật toán mới

- Thêm thuật toán Microsoft Clustering

193
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Thêm thuật toán Microsoft Naive Bayes

- Run Process để tiến hành mining

194
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

8.4. Nhận xét kết quả sau khi Mining dữ liệu.


- Thuật toán Microsoft Decision Trees
o Xem Mining Model Viewer của thuật toán Microsoft Decision Trees
o Với thuộc tính dự đoán là Cardio.
o Tỷ lệ bị bệnh tim (1) trong bộ dữ liệu là 49.98%
o Tỷ lệ không bị bệnh tim (0) trong bộ dữ liệu là 50.02%

195
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

o Với những người bị bệnh tim có tỷ lệ cao 83.54% là những bệnh nhân
có độ tuổi trên hoặc bằng 61 và có tỉ lệ cholesterol trong máu rất cao.

o Với những người bị bệnh tim có tỷ lệ cao 80.41% là những bệnh nhân
có độ tuổi trên hoặc bằng 53 và nhỏ hơn 57. Có tỉ lệ cholesterol trong
máu rất cao và tỉ lệ Glucose trong máu không phải rất cao.

196
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

o Với những người bị bệnh tim có tỷ lệ cao 79.45% là những bệnh nhân
có độ tuổi trên hoặc bằng 45 và nhỏ hơn 53. Có tỉ lệ cholesterol trong
máu rất cao, tỉ lệ Glucose trong máu rất cao và nặng hơn 85 kg.

o Với những người không bị bệnh tim có tỷ lệ cao 80.02% là những


bệnh nhân có độ tuổi trên hoặc bằng 41 và nhỏ hơn 45. Có tỉ lệ
cholesterol trong máu bình thường và cân nặng nhỏ hơn 67 kg.

197
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

o Với những người không bị bệnh tim có tỷ lệ cao 87.54% là những


bệnh nhân có độ tuổi nhỏ hơn 41. Có tỉ lệ cholesterol trong máu bình
thường và cân nặng nhỏ hơn 67 kg.

o Với những người không bị bệnh tim có tỷ lệ cao 79.47% là những


bệnh nhân có độ tuổi nhỏ hơn 41. Có tỉ lệ cholesterol trong máu bình
thường và cân nặng lớn hơn 66 kg và nhỏ 86kg.

198
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

o Dependency Network của thuật toán Microsoft Decision Tree cho


thấy những thuộc tính có ảnh hưởng tới việc bị bệnh tim.
o Những thuộc tính có ảnh hưởng giảm dần là Age -> Cholesterol ->
Weight -> Gluc

199
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

200
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Thuật toán Microsoft Clustering


o Cluster Diagram của thuật toán với Shading Variable là Cardio, value
là 1(bị mắc bệnh tim).

201
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

o Đổi tên Cluster đậm màu nhất thành High (Khả năng bị bệnh tim cao
nhất)
o Đổi tên Cluster nhạt màu nhất thành Low (Khả năng bị bệnh tim thấp
nhất)

o Với Cluster Profiles của Cluster High cho ta thấy tập lục của những
bệnh nhân bị bênh tim chiếm 83.9%
o Tập lục: Những bệnh nhân có huyết áp tâm trương (Ap_lo) bằng 100,
có huyết áp tâm thu (Ap_hi) lớn hơn 124 và nhỏ hơn 184, Cholesterol
trong máu cao hoặc rất cao, Glucose trong máu cao hoặc rất cao, giới
tính là nam, có uống rượu (Alco), độ tuổi trong khoảng 42 đến 64, có
hút thuốc (Smoke), không tập thể dục (Active), có cân nặng trên 114
kg, chiều cao trên 181 cm.

202
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

o Với Cluster Profiles của Cluster Low cho ta thấy tập lục của những
bệnh nhân không bị bênh tim chiếm 78.2%
o Tập lục: Những bệnh nhân có huyết áp tâm trương (Ap_lo) từ 63 đến
83, có huyết áp tâm thu (Ap_hi) bằng 110, Cholesterol trong máu bình
thường, Glucose trong máu bình thường, giới tính là nữ, không uống
rượu (Alco), độ tuổi trong khoảng 36 đến 64 , không hút thuốc
(Smoke), có tập thể dục (Active), có cân nặng từ 47 đến 87 kg, chiều
cao từ 149 đến 176 cm.

203
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

o Cluster Discrimination của thuật toán cho ta thấy sự tương quan giữa
2 cluster High và Low.

- Thuật toán Microsoft Naive Bayes


o Dependency Network của thuật toán Microsoft Naive Bayes cho ta
thấy các thuộc tính ảnh hưởng tới bệnh tim mạch.

204
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

205
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

o Những bệnh nhân có cholesterol bình thường thì khả năng cao sẽ
không bị bệnh tim mạch.

o Những bệnh nhân có cholesterol rất cao thì khả năng cao sẽ bị bệnh
tim mạch.

206
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

o Những bệnh nhân có glucose bình thường thì khả năng cao sẽ không
bị bệnh tim mạch.

8.5. Đánh giá các thuật toán bằng Mining Accuracy Chart
- Thiết lập thông số Input Selection với các bệnh nhân bị bệnh tim mạch

207
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Line chart cho ta thấy tỷ lệ chính xác của 3 thuật toán khi mining trường hợp
bệnh nhân bị bệnh tim.
o Microsoft Decision Tree: 0.8 Score.
o Microsoft Clustering: 0.83 Score.
o Microsoft Naive Bayes: 0.77 Score.

- Thiết lập thông số Input Selection với các bệnh nhân không bị bệnh tim
mạch
208
Kho dữ liệu và OLAP Dương Quốc Cường 17520304
IS217.K13.HTCL Mạc Huy Tú 17521196

- Line chart cho ta thấy tỷ lệ chính xác của 3 thuật toán khi mining trường hợp
bệnh nhân không bị bệnh tim.
o Microsoft Decision Tree: 0.8 Score.
o Microsoft Clustering: 0.84 Score.
o Microsoft Naive Bayes: 0.77 Score.

209

You might also like