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 OK, so are you storing information on whether your vendor is a corporation or not? You had better be if you are subject to U.S. tax law (1099 reporting). So you turn around and say that you can handle that, and the customer replies, “Great! Can you print that out along with their address as of the end of the year?” Oops — I’m betting that you don’t have past addresses, or at the very least, aren’t storing the date that the address changed. In short, you never know what a user of your system is going to ask for — try and make sure you have it. Just keep in mind that you don’t want to be moving unnecessary amounts of data up and down your network wire (see my comments on choosing a data type). If you’re storing the data just for posterity, then make sure you don’t put it in any of your application’s SELECT statements if it isn’t needed (actually, this should be your policy regardless of why you’re storing the data). Drawing Up a Quick Example Let’s walk quickly through a process of designing the invoicing database that we’ve already started with during our section on normalization. For the most part, we’re going to just be applying the diagramming tools to what we’ve already designed, but we’ll also toss in a few new issues to show how they affect our design. Creating the Database 250 If you think that there may be legal ramifications either way (both in keeping it and in getting rid of it), consult your attorney. Sometimes you’re legally obligated to keep data a certain amount of time; other times it’s best to get rid of information as soon as legally possible. Unlike a lot of the third-party diagramming tools out there, the SQL Server diagramming tools will not create the database for you — you have to already have it created in order to get as far as having the diagram available to work with. We’re not going to be playing with any data to speak of, so just create a small database called Invoice. I’ll go ahead and use the dialog in the Management Studio for the sake of this example. After right-clicking on the Databases node of my server and selecting New Database, I enter information in for a database called Invoice that is set up as 3MB in size. Since we’ve already had a chapter on creating databases (and for the sake of brevity), I’m just going to accept the defaults on all the other options, as shown in Figure 8-23.
Chapter 8: Being Normal: Normalization and Other Basic Design Issues Figure 8-23 Adding the Diagram and Our Initial Tables As we did when creating our AdventureWorks2008 diagram, expand the node for our database (it should have been added underneath the Databases node, but you may need to right click the databases node and choose “Refresh”) and accept the dialog asking if you want to add the objects needed to support diagramming. Then right-click on the Diagrams node and select New Database Diagram. The Add Table dialog pops up, but since there are no user tables in our database, we’ll just want to click Close so we wind up with a clean sheet. Now we’re ready to start adding new tables. You can either click the New Table icon on the toolbar, or right-click anywhere in the diagram and select New Table. Let’s start off by adding in the Orders table, as shown in Figure 8-24. Figure 8-24 251
- 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 and 270: Chapter 8: Being Normal: Normalizat
- Page 271 and 272: 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: 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
- Page 321 and 322: Secondary XML Indexes Chapter 9: SQ
- Page 323 and 324: occur, and that one or more non-lea
- Page 325 and 326: isn’t room on the page, SQL Serve
- Page 327 and 328: more administrator oriented and usu
- Page 329 and 330: The Database Engine Tuning Advisor
- Page 331 and 332: The output is far more self-describ
- Page 333 and 334: We use a FILLFACTOR when we need to
- Page 335: Chapter 9: SQL Server Storage and I
Chapter 8: Being Normal: Normalization and Other Basic Design Issues<br />
Figure 8-23<br />
Adding the Diagram and Our Initial Tables<br />
As we did when creating our AdventureWorks<strong>2008</strong> diagram, expand the node for our database (it should<br />
have been added underneath the Databases node, but you may need to right click the databases node<br />
and choose “Refresh”) and accept the dialog asking if you want to add the objects needed to support diagramming.<br />
Then right-click on the Diagrams node and select New Database Diagram. The Add Table dialog<br />
pops up, but since there are no user tables in our database, we’ll just want to click Close so we wind<br />
up with a clean sheet.<br />
Now we’re ready to start adding new tables. You can either click the New Table icon on the toolbar, or<br />
right-click anywhere in the diagram and select New Table. Let’s start off by adding in the Orders table,<br />
as shown in Figure 8-24.<br />
Figure 8-24<br />
251