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 bcp is a command-line program whose sole purpose in life is to move formatted data in and out of SQL Server en masse. It was around long before what has now become SSIS was thought of, and while SSIS is replacing bcp for most import/export activity, bcp still has a certain appeal for people who like commandline utilities. In addition, you’ll find an awful lot of SQL Server installations out there that still depend on bcp to move data around fast. SQL Ser ver Profiler I can’t tell you how many times this one has saved my bacon by telling me what was going on with my server when nothing else would. It’s not something a developer (or even a DBA, for that matter) tends to use every day, but it’s extremely powerful and can be your salvation when you’re sure nothing can save you. SQL Server Profiler is, in short, a real-time tracing tool. Whereas Performance Monitor is all about tracking what’s happening at the macro level — system configuration stuff — the Profiler is concerned with tracking specifics. This is both a blessing and a curse. The Profiler can, depending on how you configure your trace, give you the specific syntax of every statement executed on your server. Now imagine that you are doing performance tuning on a system with 1000 users. I’m sure you can imagine the reams of paper that would be used to print the statements executed by so many people in just a minute or two. Fortunately, the Profiler has a vast array of filters to help you narrow things down and track more specific problems, such as long-running queries, or the exact syntax of a query being run within a stored procedure. This is nice when your procedure has conditional statements that cause it to run different things under different circumstances. sqlcmd 40 As I mentioned back when we were talking about the Management Console, SQL Server has a tool to use when you want to include SQL commands and management tasks in command-line batch files — sqlcmd. You won’t see sqlcmd in your SQL Server program group. Indeed, it’s amazing how many people don’t even know that this utility is around; that’s because it’s a console application rather than a Windows program. Prior to version 7.0 and the advent of what was then called DTS (now SSIS), sqlcmd was often used in conjunction with the Bulk Copy Program (bcp) to manage the import of data from external systems. This type of use is decreasing as administrators and developers everywhere learn the power and simplicity of SSIS. Even so, there are occasionally items that you want to script into a larger command-line process. sqlcmd gives you that capability. sqlcmd can be very handy, particularly if you use files that contain scripts. Keep in mind, however, that there are tools that can accomplish much of what sqlcmd can more effectively and with a user interface that is more consistent with the other things you’re doing with your SQL Server. You can find full coverage of sqlcmd in Professional SQL Server 2008 Programming. Once again, just for history and being able to understand if people you talk SQL Server with use a different lingo, sqlcmd is yet another new name for this tool of many names. Originally, it was referred to as ISQL. In SQL Server 2000 and 7.0, it was known as osql.

PowerShell Chapter 2: Tools of the Trade PowerShell is a new feature with SQL Server 2008. PowerShell serves as an extremely robust scripting and server-navigation engine. Using PowerShell, the user can navigate all objects on the server as though they were part of a directory structure in the file system. (You even use the dir and cd style commands you use in a command window.) PowerShell is well outside the scope of a beginning title, but it is important to realize that it’s there. It is covered in more depth in Professional SQL Server 2008 Programming. Summary Most of the tools that you’ve been exposed to here aren’t ones you’ll use every day. Indeed, for the average developer, only SQL Server Management Studio will get daily use. Nevertheless it’s important to have some idea of the role that each one can play. Each has something significant to offer you. We will see each of these tools again in our journey through this book. Note that there are some other utilities available that don’t have shortcuts on your Start menu (connectivity tools, server diagnostics, and maintenance utilities), which are mostly admin related. 41

Chapter 2: Tools of the Trade<br />

bcp is a command-line program whose sole purpose in life is to move formatted data in and out of <strong>SQL</strong><br />

<strong>Server</strong> en masse. It was around long before what has now become SSIS was thought of, and while SSIS is<br />

replacing bcp for most import/export activity, bcp still has a certain appeal for people who like commandline<br />

utilities. In addition, you’ll find an awful lot of <strong>SQL</strong> <strong>Server</strong> installations out there that still depend<br />

on bcp to move data around fast.<br />

<strong>SQL</strong> Ser ver Profiler<br />

I can’t tell you how many times this one has saved my bacon by telling me what was going on with my<br />

server when nothing else would. It’s not something a developer (or even a DBA, for that matter) tends<br />

to use every day, but it’s extremely powerful and can be your salvation when you’re sure nothing can<br />

save you.<br />

<strong>SQL</strong> <strong>Server</strong> Profiler is, in short, a real-time tracing tool. Whereas Performance Monitor is all about tracking<br />

what’s happening at the macro level — system configuration stuff — the Profiler is concerned with<br />

tracking specifics. This is both a blessing and a curse. The Profiler can, depending on how you configure<br />

your trace, give you the specific syntax of every statement executed on your server. Now imagine that<br />

you are doing performance tuning on a system with 1000 users. I’m sure you can imagine the reams of<br />

paper that would be used to print the statements executed by so many people in just a minute or two.<br />

Fortunately, the Profiler has a vast array of filters to help you narrow things down and track more specific<br />

problems, such as long-running queries, or the exact syntax of a query being run within a stored procedure.<br />

This is nice when your procedure has conditional statements that cause it to run different things under<br />

different circumstances.<br />

sqlcmd<br />

40<br />

As I mentioned back when we were talking about the Management Console, <strong>SQL</strong> <strong>Server</strong> has a tool to use<br />

when you want to include <strong>SQL</strong> commands and management tasks in command-line batch files — sqlcmd.<br />

You won’t see sqlcmd in your <strong>SQL</strong> <strong>Server</strong> program group. Indeed, it’s amazing how many people don’t even<br />

know that this utility is around; that’s because it’s a console application rather than a Windows program.<br />

Prior to version 7.0 and the advent of what was then called DTS (now SSIS), sqlcmd was often used in<br />

conjunction with the Bulk Copy Program (bcp) to manage the import of data from external systems. This<br />

type of use is decreasing as administrators and developers everywhere learn the power and simplicity<br />

of SSIS. Even so, there are occasionally items that you want to script into a larger command-line process.<br />

sqlcmd gives you that capability.<br />

sqlcmd can be very handy, particularly if you use files that contain scripts. Keep in mind, however, that<br />

there are tools that can accomplish much of what sqlcmd can more effectively and with a user interface that<br />

is more consistent with the other things you’re doing with your <strong>SQL</strong> <strong>Server</strong>. You can find full coverage of<br />

sqlcmd in Professional <strong>SQL</strong> <strong>Server</strong> <strong>2008</strong> Programming.<br />

Once again, just for history and being able to understand if people you talk <strong>SQL</strong> <strong>Server</strong> with use a<br />

different lingo, sqlcmd is yet another new name for this tool of many names. Originally, it was referred<br />

to as I<strong>SQL</strong>. In <strong>SQL</strong> <strong>Server</strong> 2000 and 7.0, it was known as osql.

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

Saved successfully!

Ooh no, something went wrong!