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.

Again, many of the items here (New, Open, Save, Cut, Paste, and so on) are things that you have seen<br />

plenty of times in other Windows applications and should be familiar with, but there’s also a fair amount<br />

that’s specific to <strong>SQL</strong> <strong>Server</strong>. The main thing to notice for now is that the menus in the Management<br />

Studio are context sensitive — that is, different menus are available and what they contain changes based<br />

on which window is active in the Studio. Be sure to explore the different contextual menus you get as<br />

you explore different parts of the Management Studio.<br />

Query Window<br />

This part of the Management Studio takes the place of what was, at one time, a separate tool that was<br />

called Query Analyzer. The Query window is your tool for interactive sessions with a given <strong>SQL</strong> <strong>Server</strong>. It’s<br />

where you can execute statements using Transact-<strong>SQL</strong> (T-<strong>SQL</strong>). I lovingly pronounce it “Tee-Squeal,” but<br />

it’s supposed to be “Tee-Sequel.” T-<strong>SQL</strong> is the native language of <strong>SQL</strong> <strong>Server</strong>. It’s a dialect of Structured<br />

Query Language (<strong>SQL</strong>), and is largely compliant with modern ANSI/ISO <strong>SQL</strong> standards. You’ll find that<br />

most RDBMS products support basic ANSI/ISO <strong>SQL</strong> compatibility.<br />

Because the Query window is where we will spend a fair amount of time in this book, let’s take a more<br />

in-depth look at this tool and get familiar with how to use it.<br />

Getting Started<br />

Well, I’ve been doing plenty of talking about things in this book, and it’s high time we started doing<br />

something. To that end, open a new Query window by clicking the New Query button towards the topleft<br />

of the Management Studio, or choosing File ➪ New ➪ New Query With Current Connection from the<br />

File menu. When the Query window opens, you’ll get menus that largely match those in Query Analyzer<br />

back when that was a separate tool. We will look at the specifics, but let’s get our very first query out of<br />

the way.<br />

Start by selecting AdventureWorks<strong>2008</strong> in the database drop-down box on the <strong>SQL</strong> Editor toolbar, then<br />

type the following code into the main window of the Query window:<br />

SELECT * FROM Person.Address;<br />

Notice several things happen as you type:<br />

Chapter 2: Tools of the Trade<br />

❑ The coloring of words and phrases changes as you type.<br />

❑ As you type, the Management Studio guesses at what you’re trying to do (as shown in Figure 2-9).<br />

Utilizing IntelliSense, much like Visual Studio, <strong>SQL</strong> <strong>Server</strong> will give you hints as to what probably<br />

should come next in your code.<br />

Statement keywords should appear in blue. Unidentifiable items, such as column and table names (these<br />

vary with every table in every database on every server), are in black. Statement arguments and connectors<br />

are in red. Pay attention to how these work and learn them. They can help you catch many bugs<br />

before you’ve even run the statement (and seen the resulting error).<br />

33

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

Saved successfully!

Ooh no, something went wrong!