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 Note that you have to actually click the Execution Plan tab for it to come up and that your query results are still displayed in the way you selected. The Show Estimated Execution plan option gives you the same output as an Include Actual Execution Plan does with two exceptions: ❑ You get the plan immediately rather than after your query executes. ❑ Although what you see is the actual plan for the query, all the cost information is estimated and the query is not actually run. Under Include Actual Execution, the query is physically executed and the cost information you get is actual rather than estimated. Note that the plan in Figure 2-13 is an extremely simple execution plan. More complex queries may show a variety of branching and parallel operations. The Available Databases Combo Box Finally, take another look at the Available Databases combo box. In short, this is where you select the default database that you want your queries to run against for the current window (we changed AdventureWorks2008 to be our default database earlier). Initially, the Query window will start with whatever the default database is for the user that’s logged in (for sa, that is the master database unless someone has changed it on your system). You can then change it to any other database that the current login has permission to access. Since we’re using the sa user ID, every database on the current server should have an entry in the Available Databases combo box. The Object Explorer 38 This useful little tool enables you to navigate your database, look up object names, and even perform actions like scripting and looking at the underlying data. In the example in Figure 2-14, I’ve expanded the database node all the way down to the listing of tables in the AdventureWorks2008 database. You can drill down even farther to see individual columns (including data type and similar properties) of the tables — a very handy tool for browsing your database. Figure 2-14
SQL Ser ver Integration Ser vices (SSIS) Your friend and mine — that’s what SSIS (formerly known as Data Transformation Services or DTS) is. I simply sit back in amazement every time I look at this feature of SQL Server. To give you a touch of perspective here, I’ve done a couple of Decision Support Systems (DSS) projects over the years. (These are usually systems that don’t have online data going in and out, but instead pull data together to help management make decisions.) A DSS project gathers data from a variety of sources and pumps it into one centralized database to be used for centralized reporting. These projects can get very expensive very quickly, as they attempt to deal with the fact that not every system calls what is essentially the same data by the same name. There can be an infinite number of issues to be dealt with. These can include data integrity (what if the field has a NULL and we don’t allow NULLs?) or differences in business rules (one system deals with credits by allowing a negative order quantity, another doesn’t allow this and has a separate set of tables to deal with credits). The list can go on and on, and so can the expense. With SSIS a tremendous amount of the coding, usually in some client-side language, that had to be done to handle these situations can be eliminated or, at least, simplified. SSIS enables you to take data from any data source that has an OLE DB or .NET data provider and pump it into a SQL Server table. Be aware that there is a special OLE DB provider for ODBC. This provider allows you to map your OLE DB access directly to an ODBC driver. That means anything that ODBC can access can also be accessed by OLE DB (and, therefore, SSIS). While we’re at it, it’s also worth pointing out that SSIS, although part of SQL Server, can work against any OLE DB source and any OLE DB destination. That means that SQL Server doesn’t need to be involved in the process at all other than to provide the data pump. You could, for example, push data from Oracle to Excel, or even DB/2 to MySQL. While transferring your data, we can also apply what are referred to as transformations to that data. Transformations essentially alter the data according to some logical rule(s). The alteration can be as simple as changing a column name, or as complex as an analysis of the integrity of the data and application of rules to change it if necessary. To think about how this is applied, consider the example I gave earlier of taking data from a field that allows NULLs and moving it to a table that doesn’t allow NULLs. With SSIS you can automatically change any NULL values to some other value you choose during the transfer process. (For a number, that might be zero or, for a character, it might be something like unknown.) Bulk Copy Program (bcp) Chapter 2: Tools of the Trade If SSIS is your friend and mine, then the Bulk Copy Program, or bcp, would be that old friend that we may not see that much anymore, but really appreciate when we do. 39
- 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 72 and 73: Chapter 2: Tools of the Trade 34 Fi
- Page 74 and 75: Chapter 2: Tools of the Trade Figur
- 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
- Page 122 and 123: Chapter 4: JOINs 84 Using an INNER
- Page 124 and 125: Chapter 4: JOINs 86 Uh, oh — this
<strong>SQL</strong> Ser ver Integration Ser vices (SSIS)<br />
Your friend and mine — that’s what SSIS (formerly known as Data Transformation Services or DTS) is. I<br />
simply sit back in amazement every time I look at this feature of <strong>SQL</strong> <strong>Server</strong>. To give you a touch of perspective<br />
here, I’ve done a couple of Decision Support Systems (DSS) projects over the years. (These are<br />
usually systems that don’t have online data going in and out, but instead pull data together to help management<br />
make decisions.) A DSS project gathers data from a variety of sources and pumps it into one<br />
centralized database to be used for centralized reporting.<br />
These projects can get very expensive very quickly, as they attempt to deal with the fact that not every<br />
system calls what is essentially the same data by the same name. There can be an infinite number of issues<br />
to be dealt with. These can include data integrity (what if the field has a NULL and we don’t allow NULLs?)<br />
or differences in business rules (one system deals with credits by allowing a negative order quantity,<br />
another doesn’t allow this and has a separate set of tables to deal with credits). The list can go on and<br />
on, and so can the expense.<br />
With SSIS a tremendous amount of the coding, usually in some client-side language, that had to be done<br />
to handle these situations can be eliminated or, at least, simplified. SSIS enables you to take data from<br />
any data source that has an OLE DB or .NET data provider and pump it into a <strong>SQL</strong> <strong>Server</strong> table.<br />
Be aware that there is a special OLE DB provider for ODBC. This provider allows<br />
you to map your OLE DB access directly to an ODBC driver. That means anything<br />
that ODBC can access can also be accessed by OLE DB (and, therefore, SSIS).<br />
While we’re at it, it’s also worth pointing out that SSIS, although part of <strong>SQL</strong> <strong>Server</strong>,<br />
can work against any OLE DB source and any OLE DB destination. That means that<br />
<strong>SQL</strong> <strong>Server</strong> doesn’t need to be involved in the process at all other than to provide<br />
the data pump. You could, for example, push data from Oracle to Excel, or even DB/2<br />
to My<strong>SQL</strong>.<br />
While transferring your data, we can also apply what are referred to as transformations to that data.<br />
Transformations essentially alter the data according to some logical rule(s). The alteration can be as simple<br />
as changing a column name, or as complex as an analysis of the integrity of the data and application<br />
of rules to change it if necessary. To think about how this is applied, consider the example I gave earlier of<br />
taking data from a field that allows NULLs and moving it to a table that doesn’t allow NULLs. With SSIS<br />
you can automatically change any NULL values to some other value you choose during the transfer process.<br />
(For a number, that might be zero or, for a character, it might be something like unknown.)<br />
Bulk Copy Program (bcp)<br />
Chapter 2: Tools of the Trade<br />
If SSIS is your friend and mine, then the Bulk Copy Program, or bcp, would be that old friend that we may<br />
not see that much anymore, but really appreciate when we do.<br />
39