Beginning Microsoft SQL Server 2008 ... - S3 Tech Training
Beginning Microsoft SQL Server 2008 ... - S3 Tech Training Beginning Microsoft SQL Server 2008 ... - S3 Tech Training
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
- Page 220 and 221: Chapter 6: Constraints Dropping Rul
- Page 222 and 223: Chapter 6: Constraints 184 Restrict
- Page 225 and 226: 7 Adding More to Our Queries When I
- Page 227 and 228: Building a Nested Subquery A nested
- Page 229 and 230: While this works just fine, queries
- Page 231 and 232: We’ll go back to the AdventureWor
- Page 233 and 234: ❑ Aliases are used in both querie
- Page 235 and 236: Now let’s see this at work in our
- Page 237 and 238: So let’s take this now and apply
- Page 239 and 240: This join-based syntax, for example
- Page 241 and 242: IF NOT EXISTS (SELECT ‘True’ FR
- Page 243 and 244: The conversions can actually get a
- Page 245 and 246: there are no other roll up records
- Page 247 and 248: GROUP BY soh.OrderDate, sod.Product
- Page 249 and 250: OUTPUT $action, inserted.Year, inse
- Page 251 and 252: The long-standing, traditional view
- Page 253 and 254: 8 Being Normal: Normalization and O
- Page 255 and 256: Chapter 8: Being Normal: Normalizat
- Page 257 and 258: Chapter 8: Being Normal: Normalizat
- Page 259 and 260: Chapter 8: Being Normal: Normalizat
- Page 261 and 262: Chapter 8: Being Normal: Normalizat
- Page 263 and 264: Chapter 8: Being Normal: Normalizat
- Page 265 and 266: Chapter 8: Being Normal: Normalizat
- Page 267 and 268: Chapter 8: Being Normal: Normalizat
- Page 269: Chapter 8: Being Normal: Normalizat
- Page 273 and 274: Chapter 8: Being Normal: Normalizat
- Page 275 and 276: Chapter 8: Being Normal: Normalizat
- Page 277 and 278: Chapter 8: Being Normal: Normalizat
- Page 279 and 280: Chapter 8: Being Normal: Normalizat
- Page 281 and 282: Chapter 8: Being Normal: Normalizat
- Page 283 and 284: Chapter 8: Being Normal: Normalizat
- Page 285 and 286: Chapter 8: Being Normal: Normalizat
- Page 287 and 288: Chapter 8: Being Normal: Normalizat
- Page 289 and 290: Chapter 8: Being Normal: Normalizat
- Page 291 and 292: Chapter 8: Being Normal: Normalizat
- Page 293 and 294: Chapter 8: Being Normal: Normalizat
- Page 295 and 296: Chapter 8: Being Normal: Normalizat
- Page 297 and 298: Chapter 8: Being Normal: Normalizat
- Page 299 and 300: 9 SQL Ser ver Storage and Index Str
- Page 301 and 302: Page Splits When a page becomes ful
- Page 303 and 304: The point here is that what happens
- Page 305 and 306: Page Splits — A First Look All of
- Page 307 and 308: You may hear lots of bad things abo
- Page 309 and 310: Navigating the Tree Figure 9-4 As I
- Page 311 and 312: there was no link between the data.
- Page 313 and 314: Root Non-Leaf Level Leaf Level Figu
- Page 315 and 316: The CREATE INDEX Statement The CREA
- Page 317 and 318: FILLFACTOR When SQL Server first cr
- Page 319 and 320: works only if tempdb is on a separa
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