17.06.2013 Views

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

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

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

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5: Creating and Altering Tables<br />

Once you have the table filled out, you can save the changes, and that will create your table for you.<br />

This is really a point of personal preference, but I prefer to set the view down to just column names at<br />

this point. You can do this by clicking on the Show icon on the toolbar or, as I prefer, by right-clicking<br />

the table and choosing Table View ➪ MA Column Names. I find that this saves a lot of screen real estate<br />

and makes more room for me to work on additional tables.<br />

Now try to add in the Employees table as we had it defined earlier in the chapter. The steps should be<br />

pretty much as they were for the Customers table, with just one little hitch — we have a computed column.<br />

To deal with the computed column, just select Modify Custom again (from the right-click menu),<br />

and add the “formula” column. Then, simply add the proper formula (in this case, Salary-PriorSalary).<br />

When you have all the columns entered, save your new table (accepting the confirmation dialog) and<br />

your diagram should have two tables in it (see Figure 5-9).<br />

Figure 5-9<br />

It’s very important to understand that the diagramming tool that is included with <strong>SQL</strong> <strong>Server</strong> is not<br />

designed to be everything to everyone.<br />

Presumably, since you are reading this part of this book, you are just starting out on your database<br />

journey — this tool will probably be adequate for you for a while. Eventually, you may want to take a<br />

look at some more advanced (and far more expensive) tools to help you with your database design.<br />

Backing into the Code: The Basics of Creating Scripts<br />

with the Management Studio<br />

150<br />

One last quick introduction before we exit this chapter — we want to see the basics of having the<br />

Management Studio write our scripts for us. For now, we are going to do this as something of a quick<br />

and dirty introduction.<br />

To generate scripts, we go into the Management Studio and right-click on the database for which we<br />

want to generate scripts. (In this case, we’re going to generate scripts on our Accounting database.) On

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

Saved successfully!

Ooh no, something went wrong!