bai tap ve chuan hoa du lieu

25
CLASS EXERCISES ABOUT NORMALISATION Example – Nuts and Bolts Hardware Co-operative Nuts and Bolts Hardware Co-operative (NBHC) is a hardware chain of several stores, each trading under its own business name. Part of the stock list from Southside Hardware, one of the NBHC stores, is shown in Figure 1 below. NBHC wants to keep track of the inventory in all the stores in the co-operative because the ordering of products from suppliers is done centrally. Through that the chain can achieve higher overall quantily discounts than can be achieved by individual stores. NUTS AND BOLTS HARDWARE CO-OPERATIVE STOCK LIST Store ID: M515 Store Name: Southside Hardware Part number Part description Supplie r number Supplier Name Supplier Address Qty on hand Unit cost Total cost 3241 Bolt 2 cm 34513 Acme Bolt Co. 45 Hay Street 123 $0.50 $61.50 3541 Bolt 5 cm 34513 Acme Bolt Co. 45 Hay Street 546 $0.70 $382.20 4325 Washer 30 cm 57913 Washer Co. 7 Blacktown Road 567 $0.12 $68.04 5678 Nut 8 cm 34513 Acme Bolt Co. 45 Hay Street 342 $0.17 $58.14 1478 Screw 40 mm 00972 Best Fasteners 281 Pilbara Way 1267 $0.09 $114.03 4327 Washer 40 cm 57913 Washer Co. 7 Blacktown Rod 165 $0.15 $24.75 Total stock cost $708.66 Figure 1 – Part of a stock list from Southside Hardware Business rules 1. The sample stock list for Southside Hardware is representative of all stores. 2. Each supplier supplies several parts, but each part is supplied by only one supplier and the company wants to maintain this policy in the future. 3. Each part may be held in more than one store, for example, part number 3241 is held in store M515 (see Figure 1) but it may also be held in store M516 and M517. 1

Upload: dapxitlo-duc

Post on 28-Oct-2014

155 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Bai Tap Ve Chuan Hoa Du Lieu

CLASS EXERCISES ABOUT NORMALISATION

Example – Nuts and Bolts Hardware Co-operativeNuts and Bolts Hardware Co-operative (NBHC) is a hardware chain of several stores, each trading under its own business name.

Part of the stock list from Southside Hardware, one of the NBHC stores, is shown in Figure 1 below.

NBHC wants to keep track of the inventory in all the stores in the co-operative because the ordering of products from suppliers is done centrally. Through that the chain can achieve higher overall quantily discounts than can be achieved by individual stores.

NUTS AND BOLTS HARDWARE CO-OPERATIVE STOCK LISTStore ID: M515Store Name: Southside HardwarePart number

Part description

Supplier number

Supplier Name Supplier Address Qty on hand

Unit cost

Total cost

3241 Bolt 2 cm 34513 Acme Bolt Co. 45 Hay Street 123 $0.50 $61.50

3541 Bolt 5 cm 34513 Acme Bolt Co. 45 Hay Street 546 $0.70 $382.204325 Washer 30 cm 57913 Washer Co. 7 Blacktown Road 567 $0.12 $68.045678 Nut 8 cm 34513 Acme Bolt Co. 45 Hay Street 342 $0.17 $58.141478 Screw 40 mm 00972 Best Fasteners 281 Pilbara Way 1267 $0.09 $114.034327 Washer 40 cm 57913 Washer Co. 7 Blacktown Rod 165 $0.15 $24.75

… … … … … … … …Total stock cost $708.66

Figure 1 – Part of a stock list from Southside HardwareBusiness rules

1. The sample stock list for Southside Hardware is representative of all stores.

2. Each supplier supplies several parts, but each part is supplied by only one supplier and the company wants to maintain this policy in the future.

3. Each part may be held in more than one store, for example, part number 3241 is held in store M515 (see Figure 1) but it may also be held in store M516 and M517.

4. Qty on hand is for a particular part in a particular store.

5. The unit cost price for a particular part is the same across all stores because of the central ordering of parts.

6. Total stock cost is the sum of all total cost fields for each product.

7. Store ID is a unique identifier for a store, part number is unique for a given part and supplier number is unique for a given supplier.

1

Page 2: Bai Tap Ve Chuan Hoa Du Lieu

Before we use the NBHC example to illustrate the normalization process, let us look at a summary of the steps you need to perform to transform an un-normalised relation into third normal form(3NF) (see Figure 2)

Figure 2 – Steps required to achieve first, second and third normal forms.

2

Unnormalised Relation(0NF)

First Normal Form(1 NF)

Second Normal Form(2 NF)

Third Normal Form(3 NF)

Remove attributes which can be calculated or derived. Assign a primary key (PK). Remove repeating groups.

Check composite keys only. All non-key attributes should be fully functionally dependent on the PK Move attributes which are functionally dependent on only a subset of

the PK, into a new relation.

Check non-key attributes against each other (note that alternate keys are key attributes).

Move attributes that are only transitive dependent on the PK, into a new relation.

Page 3: Bai Tap Ve Chuan Hoa Du Lieu

FIRST NORMAL FORM (1 NF)

As we have already explained in Chapter 3, this is the only normal form which is required by the relational model. All other normal forms are additions to the relational model to create stable, non-redundant data structures.

Removing attributes that can be calculated or derived is strictly speaking not a formal requirement for 1NF but it is useful to do this at the logical model-ling stage.

Normalisation activities for NBHC

1. Gather all relevant attributes into one relation.

STORE (store ID, store name, part number, part description, supplier number, supplier name, supplier address, qty on hand, unit cost price, total product cost, total stock cost)

2. Remove attributes that can be calculated.

Total cost = qty on hand x unit cost price

Total stock cost = Sum of all total costs

After removal of these two attributes, the relation is:

STORE (store ID, store name, part number, part description, supplier number, supplier name, supplier address, qty on hand, unit cost price)

3. Assign a primary key (PK)

The attribute(s) that we select have to be unique for each store. The store ID conforms to that so the relation is now:

STORE ( store ID, store name, part number, part description supplier number, supplier name, supplier address, qty on hand, unit cost price)

4. Remove repeating groups.

A repeating group of attributes is defined as follows:

An attribute, A, is repeating, if for a specific value of the primary key, there are multiple values of the attribute A associated with this PK.

For NBHC it is clear form Figure 1, for example, that for the store ID primary key value of ‘M515’, there are multiple values of the attributes: part number, part description, supplier number, supplier name, supplier address, qty on hand and unit cost price associated with it.

All these attributes need to be need to be moved to another relation. The primary key of the new relation is usually a composite key – a concatenation of the primary key of the original relation and a unique identifier for the repeating group. In the NBHC example, the unique identifier for the repeating group is part number, that is, the primary key for the new relation is store ID, part number. The resulting relations are now:

STORE ( store ID, store name)

PART ( store ID, part number, part description, supplier number, supplier name, supplier address, qty on hand, unit cost price)

These two relations are now in first normal form (1NF). Note that we already have encountered the repeating group concept in Chapter 3. The relational model prescribes that repeating groups are not permitted, that is, 1NF is and integral part of the relational model.

3

Page 4: Bai Tap Ve Chuan Hoa Du Lieu

SECOND NORMAL FORM (2NF)

Relations are in 2NF, if they are in 1NF and all non-key attributes are fully functionally dependent on the primary key. We only have to check composite keys – all relations which have a single attribute primary key are automatically in 2 NF if they are in 1NF.

2NF activities for NBHC

1. Relations automatically in 2 NF

Recall from the normalization rules in Figure 2 that any 1NF relation without a composite primary key is automatically in 2 NF. Hence, the STORE relation is already in 2NF.

2. Functional dependencies for relations with a composite primary key

The PART relation has a composite primary key, so according to our normalization rules, we need to check for dependencies.

The function dependencies, according to the business rules given in the problem description, are shown in Figure 3.

PART(store ID, part number, part description, supplier number, supplier name, supplier address, qty on hand, unit cost price)

Figure 3 – Functional dependencies for the PART relation

3. Move the partial key dependencies into a new relation

Figure 3 shows that qty on hand is fully functionally dependent on the whole of the primary key while the remainder of the attributes are only dependent on a subset of the primary key – part number.

The attributes which are not fully functionally dependent on the whole of the primary key must be moved to a new relation. The unique identifier of the new relation is that part of the original primary key on which the other attributes are dependent.

The PART relation now splits into PART and STOREC PART.

PART (part number, part description, supplier number, supplier name, supplier address, unit cost price)

STORED PART ( store ID, part number, qty on hand)

All relations are now:

STORE ( store ID, store name)

PART (part number, part description, supplier number, supplier name, supplier address, unit cost price)

STORED PART ( store ID, part number, qty on hand)

These relations are in second normal form (2NF)

4

Page 5: Bai Tap Ve Chuan Hoa Du Lieu

THIRD NORMAL FORM (3NF)

For 3NF you only investigate dependencies between non-key attributes-transitive dependency. Remember that alternate keys, if any, are key attributes by definition. In the NBHC problem there are no alternate keys.

Transitive dependence is defined as:

If attribute A is functionally dependent on another non-key attribute B, which is dependent on the primary key, then attribute A is said to be transitive dependent on the primary key, that is, dependent on the primary key through attribute B.

3NF activities for NBHC

1. List dependencies between non-key attributes.

For the NBHC problem, these are shown in Figure 4.

Figure 4 – Transitive dependencies for the NBHC problem

Note that in each of STORE and STORED PART there is only one non-key attribute, that is, there is no possibility for transitive dependencies to occur.

In PART, all non-key attributes are dependent on the primary key part number, but supplier name and supplier address are also dependent on supplier number. This means that these two attributes are transitive dependent (via supplier number) on the PK (part number). They need to be moved to a new relation.

The revised set of relations, showing foreign keys as well, are shown in Figure 5. These relations are now in 3NF.

STORE (store ID, store name)

STORED PART (store ID, part number , qty on hand)

PART (part number, part description, supplier number, unit cost price)

SUPPLIER (supplier number, supplier name, supplier address)

Figure 5 – 3NF relations for the NBHC problem

5

STORE (store ID, store name)(There are no non-key attribute dependencies here)

STORED PART (store ID, part number, qty on hand)(There are no non-key attribute dependencies here)

PART (part number, part description, supplier number, supplier name, supplier address, unit cost price)

;;;;;;;

Page 6: Bai Tap Ve Chuan Hoa Du Lieu

Exercise 1:

Using the following data, create an unnormalised relation, then normalize it to 1NF, 2NF and 3NF. Use the business rules, which you can infer from the data. If necessary, state any assumptions which you make.

ID# Supp code

Supplier Description Dept ID Department name Opening WDV

Dep rate

Dep amt Loc ID

Location

202 L02 Lincoln Welder 400 Amp FAB Fabrication Shop $2760 20% $552 WE Welshpool296 SC1 Schoettel Deepwater

bargeFEH P&E Hire $221000 10% $22100 VI Varanus Is.

328 C03 Colchester Lathe 1500 BC MEC Mechanical Shop $8750 10% $875 KW Kewdale419 F11 Fluke Multimeter ELE Electrical Shop $430 20% $86 BE Belmont790 L02 Lincoln Welder 400 Amp FAB Fabrication Shop $2760 20% $552 WE Welshpool987 M01 Mitutoyo Micrometer MEC Mechanical Shop $440 5% $22 KW Kewdale1290 AS1 Allstar Satcom 2000 PEH P&E Hire $7200 30% $2160 TH Thailand1333 L02 Lincoln Welder 300 Amp MEC Mechanical Shop $2440 15% $366 KW Kewdale5693 C03 Colchester Lathe 1800 BC MEC Mechanical Shop $9900 10% $990 KW Kewdale6785 T07 Tektronics Oscilloscope ELE Electrical Shop $5700 10% $570 BE Belmont6788 L02 Lincoln Welder 400 Amp PEH P&E Shop $2760 20% $552 KW Kwinana

Exercise 2:

Using the following data, create an unnormalised relation, then normalize it to 1NF, 2NF and 3NF. Use the business rules which you can infer from the data. If necessary, state any assumptions which you make.

Duty code

A/C ID

A/C type

Aircraft make

Service description

Man ID

Manufacturer Ctry Base ID

Based at State

TR 003 C130 Hercules

Transport LO Lockheed USA RI Richmond NSW

SR 007 UH-1 Iroquois SAR BE Bell USA PE Pearce WATR 009 C130 Hercule

sTransport LO Lockheed USA RI Richmond NSW

T 026 A331B Macchi Trainer AM AerMacchi Italy PE Pearce WAT 027 A331B Macchi Trainer AM AerMacchi Italy PE Pearce WAF 032 F/A18 Hornet Fighter MD McDonnell-

DouglassUSA AM Amberley Qld

F 037 F/A18 Hornet Fighter MD McDonnell-Douglass

USA AM Amberley Qld

T 072 A331B Macchi Trainer AM AerMacchi Italy PE Pearce WAMR 076 P3B Orion Mar. recon LO Lockheed USA ED Edinburgh SAMR 088 P3B Orion Mar. recon LO Lockheed USA ED Edinburgh SAF 112 FA-18 Hornet Fighter MD McDonnell-

DouglasUSA AM Amberley Qld

6

Page 7: Bai Tap Ve Chuan Hoa Du Lieu

Exercise 3:Based on the following Sales Invoice Form, collect data from the form and normalise your relations into 3NF.

MowerMan Pty. Ltd. Sales Invoice Invoice#: 1400 South Road,Clovelly Park, 5042Tel. no. 8277 7000Fax no. 8277 7888

Customer No: ___________________________ Date:_____________

Customer name: ___________________________________________________

Customer address: __________________________________________________

Suburb: ____________ State: ________ Post Code: ________

Phone No: __________________

ProductNo ProductName Qty Price Total

Sales Total

Comments:

**Conditions applied for warranty services. See the back page for details.

7

Page 8: Bai Tap Ve Chuan Hoa Du Lieu

Exercise 4:Based on the following Batch Order Form, collect data from the form and normalise your relations into 3NF.

MowerMan Pty. Ltd. Batch Orders Batch Order No:_____1400 South Road, Action DateClovelly Park, 5042Tel. no. 8277 7000Fax no. 8277 7888

Customer No: ___________________

Customer name: ____________________________ Date:_____________

Customer address: ___________________________________________________

Suburb: ____________ State : ________ Post Code: ________

Phone no: ______________

ReOrder No OrdDate ProdNo ProdName SupplierNo SupplierName Qty Arrived?

Comments: _____________________________________________________

_____________________________________________________

Staff responsible: _________________

8

Placed order

In stock

Informed customerPicked up

Page 9: Bai Tap Ve Chuan Hoa Du Lieu

Exercise 5:Given the following forms, Normalise the information into 3NF.

Form F15

Purchase OrderACME TRADING COMPANY29-34 ASHVALE ROAD, NORTH ADELAIDES.A. 5000Tel No: 8278 8888

Supplier No: 213 Date: 19/3/2001Supplier Name: Peter Toolings Co. Ltd. Order No: 19-3-2001-1 370 Main North Road, This Purchase Order No. must be

Regency Park S.A. quoted on all Packing slips, Packages, Bills of Lading, Invoices and Correspondence.

Quantity Description Part No. /

Code No.Cost Per Unit Cost

10

5

Metrinch Socket & combination Spanner Set

Bosch 2 Speed Hammer Drill

5214-276

PSB-400-2

650.00

500.00

65.00

100.00

Total: 1150.00

Deliver to: Goods received section

To be delivered by: 10/3/2001

Terms of delivery: 30 days on purchase order

Req. No.: 12345

Charge A/C No.: 4213-CJ

Conditions1. All invoices must be passed to above address.2. Delivery Advice Notes must accompany goods.3. For Further Conditions see overleaf

Signed for the company

John Smith

Authorised Purchasing Officer

9

Page 10: Bai Tap Ve Chuan Hoa Du Lieu

Form F14

Purchase RequisitionACME TRADING COMPANY29-34 ASHVALE ROAD, NORTH ADELAIDES.A. 5000Tel No: 8278 8888

Staff No: 1234 Date: 12/3/2001Staff Name: Jim Jones Requsition No: 12345Department Name: Maintenance Section (Office use)

Quantity Description Preferred Supplier

Part No. / Code No.

Estimated Cost

Per Unit Cost

10

5

Metrinch Socket & combination Spanner Set

Bosch 2 Speed Hammer Drill

5214-276

PSB-400-2

650.00

500.00

65.00

100.00

Total: 1150.00

Deliver to: Advise the section when goods arrive

Required by: 10/3/2001

Charge A/C No.: 4213-CJ

Conditions1. All requisition must be approved by the head of the

department2. If no preferred supplier, the purchasing section will

find a supplier based on the company purchasing policy.

Approved By:

Section Head

10

Page 11: Bai Tap Ve Chuan Hoa Du Lieu

Exercise 6:Given the following forms, Normalise the information into 3NF.

MailHome Company Ltd.18 First Street,Panorama S.A. 5041Tel no: 8272 8000Fax no: 8272 8001Web site: www.mailhome.com.au

Customer Order Order No: 2453162

Order Date: 15/3/2000

Sales Rep No: 15Sales Rep Name: Jim Richardson

Customer Name:Mary JonesJackson Video Production Company Ltd.80A Hutt Street, Adelaide. S.A. 5000Tel no: 2712 9843

Credit Card Type: VISA

Card Holder Name: M. G. Jones

Card No: 4509 6512 7610

Expiry Date: 30/9/2000

Comments: Requested all items to be packaged with the original cardboard boxes.

Item No. Item Name Qty Price Line Total12000-27 Arcosteel 8 Piece Knife Block Set 1 109.95 109.9512000-35 Pack and Roll Folding Cart 1 29.95 29.9512000-51 Bordex 72 Bottle Wine Rack 2 129.00 288.00

Total: 427.90

Exercise 7:Các nhân viên của bộ phận IT dùng form sau để lưu lại việc cài đặt phần mềm trên mỗi máy tính. Form này có thể được dùng như nguồn thu thập dữ liệu để thiết kết CSDL. Sinh viên hãy dẫn ra các quan hệ chuẩn 3NF. Ghi rõ cách thực hiện.

Computer Software Installation Form

Computer ID: 185 Model: Evo N1000C

Computer Description: Compaq Small Form Factor Serial No: 2145278

Brand: Compaq CPU: P4 CPU Speed: 2.0 GHz

Staff ID (Computer used by): 51398 Staff Name: Jim Moore

Software id

Software name

Version Vendor Media Install Date

Installed by IT Services Staff

Un-installed Date

Un-installed by IT Services Staff

018-34 Windows O/S

XP Microsoft CD 04/04/2004 Jason B.

018-50 MS-SQL Server

2000 Microsoft CD 05/04/2004 Jason B.

021-04 ClearQuest 2003.0.1.0 Rational CD 07/04/2004 Steve M. 09/04/2004 Jason B.025-03 Nero 6.7.0.1.0 Ahead

softwareCD 10/04/2004 Deb. H. 15/04/2004 Steve M.

021-04 ClearQuest 2003.0.1.0 Rational CD 15/04/2004 Deb. H.

11

Page 12: Bai Tap Ve Chuan Hoa Du Lieu

Exercise 8:

Các nhân viên ở bộ phận IT dùng màn hình (screen) sau để hiển thị các cuộc gọi và các hành động xử lý của họ. Màn hình này có thể được dùng như nguồn thu thập dữ liệu để thiết kết CSDL. Sinh viên hãy dẫn ra các quan hệ chuẩn 3NF. Ghi rõ cách thực hiện..

Call Enquiry Screen

Call ID: 187 Call Date: 20-10-2004 Priority: 2__

Action Description: ____The Rational ClearCase client does not run due to license server problem

Model: Evo N1000C Computer Description: Compaq Small Form Factor Serial No : 2145278

Brand: Compaq CPU : P4 CPU speed: 2.0 GHz

Client No: _59 Client name: John Smith Office Location: 5F Room 2 West Wing

Work Group: HRD Work Group Name: Human Resource Department___

Display of Action History:

Action ID

Action Description IT Staff ID (Responded)

IT Staff name

Start Date Start Time

End Date

End Time

Call ID

Action Status

Referred by Action ID

150 Change Regional setting in ClearCase 392 Mary

Jones 22/10/04 10:00:00 22/10/04 10:20:00 187Need further Action

200 Rejoin Domain and test client setting 377 Jack Li 23/10/04 11:00:00 23/10/04 11:15:00 187

Need further Action

150

300Reinstall Rational ClearCase and set new parameters

398Jim Moore

27-10/04 10:00:00 27/10/04 10:15:00 187 Closed 200

12

Page 13: Bai Tap Ve Chuan Hoa Du Lieu

Exercise 9:

Tư vấn viên đã thu thập được form sau. Form này có thể được dùng như nguồn dữ liệu để thiết kết CSDL. Sinh viên hãy dẫn ra các quan hệ chuẩn 3NF. Ghi rõ cách thực hiện

Rooffy Real Estate Company Ltd.1 Main Street, Adelaide 5000.Phone: 8200 8000Tax: 8200 8001Web site: www.rooffy.com.au

Property Open Inspection Schedule

Property: Property ID: (1/2/00–2345)Address: Unit 4, 28 Boothy street, Panorama 5041

Representative:Rep ID: 1001Rep Name: Ryan Green

Expected Price:150,000 – 165,000

OwnerID: 2451Owner Name: Joe HarpasOwner Address: 15 King Street, Panorama 5041.

Home Phone No8212 6723

Work Phone No:8181 7328

Next Auction:Auction ID: 25/3/2000 - 5Date: 25/3/2000 Time: 12:00 noon

Mobile Phone:0414 383318

Fax. No:

Day Date Begin Time End Time Sales Agent Owner commentsSat 4/3/2000 1:00pm 1:45pm Ryan Green Air condition needs repair.Sun 5/3/2000 2:00pm 2:45pm Mary JordanFri 10/3/2000 12:00pm 12:45pm John JoansSun 12/3/2000 1:00pm 1:45pm Ryan Green In Alice Spring. Contactable at

08 9232 2754Sat 18/3/2000 3:00pm 3:45pm Mary Jordan

13