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 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

<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

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

Saved successfully!

Ooh no, something went wrong!