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 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
- 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 76 and 77: Chapter 2: Tools of the Trade Note
- 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
- Page 126 and 127: Chapter 4: JOINs How It Works Unlik
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.