Welcome to Beginning T-SQL 2008. This book introduces you to the language known as T-SQL, also called Transact-SQL. It’s the fundamental language that you need to know in order to work productively with Microsoft’s database management system known as SQL Server. Almost everything that you do in SQL Server boils down to T-SQL commands, whether you write them yourself or whether a tool generates them for you. If you want to be successful in a career involving SQL Server, then it helps to master the underlying language.
To whet your appetite and to give you an idea of what you’re in for, here is a simple example of a T-SQL statement. It’s a simple query to list all the databases hosted on SQL Server:
SELECT name FROM sys.databases;
I wrote this book because I love working with T-SQL and love teaching others how to use it. I was introduced to SQL Server in the run up to year 2000. I was enamored with the power of SQL Server and with the expressiveness built into the T-SQL language. The amount of work that you can get done in a single statement of T-SQL versus large blocks of code in other languages is simply amazing. Using TSQL, you can generate complex reports from a single statement, embed business logic in your database, create maintenance scripts to automate administrative tasks, and do much, much more.
The approach I take in this book is to begin with a review of some fundamental database concepts. Why? Because you need to understand how SQL Server stores the data before you begin to write queries against it. Then I move on to writing some simple queries, giving you the tools you need to begin extracting useful data from a database. From there we move on to manipulating data because most databases are not static; they are updated frequently. I then show you the programming logic features of T-SQL that you can use to create scripts and database objects so you can do more with T-SQL than just write single statements. Finally, I introduce you to some new, more advanced T-SQL features so that you can take advantage of cutting-edge techniques that many developers haven’t even heard about.
Almost everything in SQL Server boils down to T-SQL sooner or later. Don’t think you can escape T-SQL by using tools. Tools that generate code for you are great, but tools break. And whenthings go wrong, that’s your chance to really shine–if you know T-SQL. Those who understand T-SQL can look at what a tool or a utility is doing and understand why the generated code is failing. Those without T-SQL knowledge will be seeking you out, because you’ll be the one to diagnose and solve the problem. You’ll also be able to get work done without fancy and expensive tool sets. With T-SQL, you can be productive in almost any circumstance.