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

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

cdn.s3techtraining.com
from cdn.s3techtraining.com More from this publisher
17.06.2013 Views

Chapter 2: Tools of the Trade 34 Figure 2-9 Note that IntelliSense is new with SQL Server 2008. While they have done a terrific job with it, it is not without some peculiarities created by the nature of SQL versus other languages. Of particular importance is what help you can get when you’re adding columns to be selected. We’ll see more about the syntax of this in later chapters, but SQL syntax calls for column names before the names of the tables those columns are sourced from. The result is problematic for IntelliSense as, when you are typing your column names, the tool has no way of knowing what tables you’re trying to get those columns from (and therefore no way of giving you appropriate hints). If you’re desperate, you can get around this by skipping ahead to add the table names, then coming back to fill in the column names. The check-mark icon (Parse) on the SQL Editor toolbar represents another simple debugging item that quickly parses the query for you without actually attempting to run the statement. If there are any syntax errors, this should catch them before you see error messages. A debugger is available as another way to find errors. We’ll look at that in depth in Chapter 12. Now click the Execute button (with the red exclamation point next to it) on the toolbar. The Query window changes a bit, as shown in Figure 2-10. Notice that the main window has been automatically divided into two panes. The top is your original query text; the bottom is called the results pane. In addition, notice that the results pane has a tab at the top of it. Later on, after we’ve run queries that return multiple sets of data, you’ll see that we can get each of these results on separate tabs; this can be rather handy, because you often don’t know how long each set of data, or result set, is. The terms result set and recordset are frequently used to refer to a set of data that is returned as a result of some command being run. You can think of these words as interchangeable. Now change a setting or two and see how what we get varies. Take a look at the toolbar above the Query window and check out a set of three icons, highlighted in Figure 2-11. These control the way you receive output. In order, they are Results to Text, Results to Grid, and Results to File. The same choices can also be made from the Query menu under the Results To submenu.

Figure 2-10 Results to Text Figure 2-11 Chapter 2: Tools of the Trade The Results to Text option takes all the output from your query and puts it into one page of text results. The page can be of virtually infinite length (limited only by the available memory in your system). Before discussing this further, rerun that previous query using this option and see what you get. Choose the Results to Text option and rerun the previous query by clicking Execute, as shown in Figure 2-12. The data that you get back is exactly the same as before. It’s just given to you in a different format. I use this output method in several scenarios: ❑ When I’m only getting one result set and the results have only fairly narrow columns ❑ When I want to be able to save my results in a single text file ❑ When I’m going to have multiple result sets, but the results are expected to be small, and I want to be able to see more than one result set on the same page without dealing with multiple scrollbars 35

Chapter 2: Tools of the Trade<br />

34<br />

Figure 2-9<br />

Note that IntelliSense is new with <strong>SQL</strong> <strong>Server</strong> <strong>2008</strong>. While they have done a terrific job with it, it is not<br />

without some peculiarities created by the nature of <strong>SQL</strong> versus other languages. Of particular importance<br />

is what help you can get when you’re adding columns to be selected. We’ll see more about the syntax of<br />

this in later chapters, but <strong>SQL</strong> syntax calls for column names before the names of the tables those columns<br />

are sourced from. The result is problematic for IntelliSense as, when you are typing your column names,<br />

the tool has no way of knowing what tables you’re trying to get those columns from (and therefore no<br />

way of giving you appropriate hints). If you’re desperate, you can get around this by skipping ahead to<br />

add the table names, then coming back to fill in the column names.<br />

The check-mark icon (Parse) on the <strong>SQL</strong> Editor toolbar represents another simple debugging item that<br />

quickly parses the query for you without actually attempting to run the statement. If there are any syntax<br />

errors, this should catch them before you see error messages. A debugger is available as another way to<br />

find errors. We’ll look at that in depth in Chapter 12.<br />

Now click the Execute button (with the red exclamation point next to it) on the toolbar. The Query window<br />

changes a bit, as shown in Figure 2-10.<br />

Notice that the main window has been automatically divided into two panes. The top is your original<br />

query text; the bottom is called the results pane. In addition, notice that the results pane has a tab at the<br />

top of it. Later on, after we’ve run queries that return multiple sets of data, you’ll see that we can get<br />

each of these results on separate tabs; this can be rather handy, because you often don’t know how long<br />

each set of data, or result set, is.<br />

The terms result set and recordset are frequently used to refer to a set of data that is<br />

returned as a result of some command being run. You can think of these words as<br />

interchangeable.<br />

Now change a setting or two and see how what we get varies. Take a look at the toolbar above the Query<br />

window and check out a set of three icons, highlighted in Figure 2-11.<br />

These control the way you receive output. In order, they are Results to Text, Results to Grid, and Results<br />

to File. The same choices can also be made from the Query menu under the Results To submenu.

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

Saved successfully!

Ooh no, something went wrong!