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 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
- Page 22 and 23: Contents xx Correlated Subqueries 1
- Page 24 and 25: Contents xxii SORT_IN_TEMPDB 280 ON
- Page 26 and 27: Contents xxiv Control-of-Flow State
- Page 28 and 29: Contents xxvi How the SQL Ser ver L
- Page 30 and 31: Contents Chapter 16: A Brief XML Pr
- Page 32 and 33: Contents Chapter 19: Pla ying Admin
- Page 34 and 35: Introduction The beginning user wil
- Page 36 and 37: Introduction ❏ We show file names
- Page 38 and 39: Introduction xxxvi ❏ Understand t
- Page 40 and 41: Chapter 1: RDBMS Basics: What Makes
- Page 42 and 43: Chapter 1: RDBMS Basics: What Makes
- Page 44 and 45: Chapter 1: RDBMS Basics: What Makes
- Page 46 and 47: Chapter 1: RDBMS Basics: What Makes
- Page 48 and 49: Chapter 1: RDBMS Basics: What Makes
- Page 50 and 51: Chapter 1: RDBMS Basics: What Makes
- Page 52 and 53: Chapter 1: RDBMS Basics: What Makes
- Page 54 and 55: Chapter 1: RDBMS Basics: What Makes
- Page 56 and 57: Chapter 1: RDBMS Basics: What Makes
- Page 58 and 59: Chapter 1: RDBMS Basics: What Makes
- Page 60 and 61: Chapter 2: Tools of the Trade 22 My
- Page 62 and 63: Chapter 2: Tools of the Trade ❑ S
- Page 64 and 65: Chapter 2: Tools of the Trade 26 Ke
- Page 66 and 67: Chapter 2: Tools of the Trade 28 Th
- Page 68 and 69: Chapter 2: Tools of the Trade 30 lo
- Page 70 and 71: Chapter 2: Tools of the Trade 32 3.
- Page 74 and 75: Chapter 2: Tools of the Trade Figur
- Page 76 and 77: Chapter 2: Tools of the Trade Note
- Page 78 and 79: Chapter 2: Tools of the Trade bcp i
- Page 81 and 82: 3 The Foundation Statements of T-SQ
- Page 83 and 84: asic SELECT statement. Fire up the
- Page 85 and 86: Now let’s try taking a little bit
- Page 87 and 88: very few of your tables will have s
- Page 89 and 90: Operator Example Usage Effect ALL,
- Page 91 and 92: Chapter 3: The Foundation Statement
- Page 93 and 94: WHERE SalesOrderID IN (43660, 43670
- Page 95 and 96: AVG This one is for computing avera
- Page 97 and 98: efore, but remove the two AS keywor
- Page 99 and 100: You’ll get a result that is a bit
- Page 101 and 102: What if we want to place conditions
- Page 103 and 104: Let’s say, for example, that we w
- Page 105 and 106: Chapter 3: The Foundation Statement
- Page 107 and 108: City varchar(20) NOT NULL, State ch
- Page 109 and 110: for it in the INSERT statement. For
- Page 111 and 112: And sure enough, we get back the on
- Page 113 and 114: Chapter 3: The Foundation Statement
- Page 115 and 116: Chapter 3: The Foundation Statement
- Page 117: Chapter 3: The Foundation Statement
- Page 120 and 121: Chapter 4: JOINs 82 returned is in
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.