Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

cdn.s3techtraining.com
from cdn.s3techtraining.com More from this publisher
17.06.2013 Views

Chapter 8: Being Normal: Normalization and Other Basic Design Issues 232 Figure 8-5 Order No (PK) Line Item (PK) Part No Qty Unit Price Total Price 100 100 100 100 101 102 102 102 103 103 103 Order No (PK) Order Date Customer No 1 2 3 4 1 1 2 3 1 2 3 100 101 102 103 1A4536 0R2400 0R2403 4I5436 3X9567 8G9200 8G5437 3H6250 2P5523 1/1/1999 1/1/1999 1/1/1999 1/1/1999 1A4536 0R2400 0R2403 4I5436 3X9567 8G9200 8G5437 3H6250 8G9200 2P5523 3X9567 By using the join syntax that we learned back in Chapter 4, we can relate one product to the many orders that it’s been part of, or we can go the other way and relate an order to all the products on that order. 5 4 4 1 1 7 1 1 40 1 1 54545 12000 66651 54545 Part No (PK) Description wt Flange Injector Injector Head Pump Fan Fan Control Housing 15 27 29 750 62.50 12 15 32 12 165 42 6 .5 .5 3 5 3 3 5 1 75 108 116 750 62.50 84 15 32 480 165 42

Chapter 8: Being Normal: Normalization and Other Basic Design Issues Let’s move on now to our second example — one where we create an associate table from scratch just so we can have a many-to-many relationship. We’ll take the example of a user and a group of rights that a user can have on the system. We might start with a Permissions table that looks something like this: PermissionID Description 1 Read 2 Insert 3 Update 4 Delete Then we add a Users table: UserID Full Name Password Active JohnD John Doe Jfz9..nm3 1 SamS Sam Spade klk93)md 1 Now comes the problem — how do we define what users have which permissions? Our first inclination might be to just add a column called Permissions to our Users table: UserID Full Name Password Permissions Active JohnD John Doe Jfz9..nm3 1 1 SamS Sam Spade klk93)md 3 1 This seems fine for only a split second, and then a question begs to be answered — what about when our users have permission to do more than one thing? In the older, flat file days, you might have just combined all the permissions into the one cell, like: UserID Full Name Password Permissions Active JohnD John Doe Jfz9..nm3 1,2,3 1 SamS Sam Spade klk93)md 1,2,3,43 1 233

Chapter 8: Being Normal: Normalization and Other Basic Design Issues<br />

232<br />

Figure 8-5<br />

Order No (PK) Line Item (PK) Part No Qty Unit Price Total Price<br />

100<br />

100<br />

100<br />

100<br />

101<br />

102<br />

102<br />

102<br />

103<br />

103<br />

103<br />

Order No (PK) Order Date Customer No<br />

1<br />

2<br />

3<br />

4<br />

1<br />

1<br />

2<br />

3<br />

1<br />

2<br />

3<br />

100<br />

101<br />

102<br />

103<br />

1A4536<br />

0R2400<br />

0R2403<br />

4I5436<br />

3X9567<br />

8G9200<br />

8G5437<br />

3H6250<br />

2P5523<br />

1/1/1999<br />

1/1/1999<br />

1/1/1999<br />

1/1/1999<br />

1A4536<br />

0R2400<br />

0R2403<br />

4I5436<br />

3X9567<br />

8G9200<br />

8G5437<br />

3H6250<br />

8G9200<br />

2P5523<br />

3X9567<br />

By using the join syntax that we learned back in Chapter 4, we can relate one product to the many orders<br />

that it’s been part of, or we can go the other way and relate an order to all the products on that order.<br />

5<br />

4<br />

4<br />

1<br />

1<br />

7<br />

1<br />

1<br />

40<br />

1<br />

1<br />

54545<br />

12000<br />

66651<br />

54545<br />

Part No (PK) Description wt<br />

Flange<br />

Injector<br />

Injector<br />

Head<br />

Pump<br />

Fan<br />

Fan<br />

Control<br />

Housing<br />

15<br />

27<br />

29<br />

750<br />

62.50<br />

12<br />

15<br />

32<br />

12<br />

165<br />

42<br />

6<br />

.5<br />

.5<br />

3<br />

5<br />

3<br />

3<br />

5<br />

1<br />

75<br />

108<br />

116<br />

750<br />

62.50<br />

84<br />

15<br />

32<br />

480<br />

165<br />

42

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!