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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5: Creating and Altering Tables<br />

is no model, so we need to provide some more specifics in the form of columns, data types, and special<br />

operators.<br />

Let’s look at more extended syntax:<br />

CREATE TABLE [database_name.[owner].]table_name<br />

( <br />

[[DEFAULT ]<br />

|[IDENTITY [(seed, increment) [NOT FOR REPLICATION]]]]<br />

[ROWGUIDCOL]<br />

[COLLATE ]<br />

[NULL|NOT NULL]<br />

[]<br />

|[column_name AS computed_column_expression]<br />

|[]<br />

[,...n]<br />

)<br />

[ON {|DEFAULT}]<br />

[TEXTIMAGE_ON {|DEFAULT}]<br />

Now that’s a handful — and it still has sections taken out of it for simplicity’s sake! As usual, let’s look at<br />

the parts, starting with the second line (we’ve already seen the top line).<br />

Table and Column Names<br />

124<br />

What’s in a name? Frankly — a lot. You may recall that one of my first soapbox diatribes was back in<br />

Chapter 2 and was about names. I promised then that it wouldn’t be the last you heard from me on the<br />

subject, and this won’t be either.<br />

The rules for naming tables and columns are, in general, the same rules that apply to all database<br />

objects. The <strong>SQL</strong> <strong>Server</strong> documentation will refer to these as the rules for identifiers, and they are the same<br />

rules we observed at the end of Chapter 1. The rules are actually pretty simple; what we want to touch<br />

on here, though, are some notions about how exactly to name your objects — not specific rules governing<br />

what <strong>SQL</strong> <strong>Server</strong> will and won’t accept for names, but how to go about naming your tables and<br />

columns so that they are useful and make sense.<br />

There are a ton of different “standards” out there for naming database objects — particularly tables and<br />

columns. My rules are pretty simple:<br />

❑ For each word in the name, capitalize the first letter and use lowercase for the remaining letters.<br />

❑ Keep the name short, but make it long enough to be descriptive.<br />

❑ Limit the use of abbreviations. The only acceptable use of abbreviations is when the chosen<br />

abbreviation will be recognized by everyone. Examples of abbreviations I use include “ID” to<br />

take the place of identification, “No” to take the place of number, and “Org” to take the place of<br />

organization. Keeping your names of reasonable length will require you to be more cavalier<br />

about your abbreviations sometimes, but keep in mind that, first and foremost, you want clarity<br />

in your names.

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

Saved successfully!

Ooh no, something went wrong!