Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL



This book walks you through your first steps in T-SQL (also known as Transact-SQL), which is the Microsoft SQL Server dialect of the standard ANSI-SQL language. You’ll learn the theory behind T-SQL querying and programming, how to develop T-SQL code to query and modify data, and get an overview of programmable objects.

Although this book is intended for beginners, it is not merely a step-by-step book. It goes beyond the syntactical elements of T-SQL and explains the logic behind the language and its elements.

Occasionally the book covers subjects that may be considered advanced for readers who are new to T-SQL; therefore, those sections are optional reading. If you already feel comfortable with the material discussed in the book up to that point, you may want to tackle the more advanced subjects; otherwise, feel free to skip those sections and return to them after you’ve gained more experience. The text will indicate when a section may be considered more advanced and is provided as optional reading.

Many aspects of SQL are unique to the language, and are very different from other programming languages. This book helps you adopt the right state of mind and gain a true understanding of the language elements. You learn how to think in terms of sets and follow good SQL programming practices.

The book is not version-specific; it does, however, cover language elements that were introduced in recent versions of SQL Server, including SQL Server 2008. When I discuss language elements that were introduced recently, I specify the version in which they were added.

To complement the learning experience, the book provides exercises that enable you to practice what you’ve learned. The book occasionally provides optional exercises that are more advanced. Those exercises are intended for readers who feel very comfortable with the material and want to challenge themselves with more difficult problems. The optional exercises for advanced readers are labeled as such.

P2.1. Who This Book Is For

This book is intended for T-SQL programmers, DBAs, architects, analysts, and SQL Server power users who just started working with SQL Server and need to write queries and develop code using Transact-SQL.

P2.2. What This Book Is About

The book starts with both a theoretical background to T-SQL querying and programming in Chapter 1, laying the foundations for the rest of the book, and also coverage of creating tables and defining data integrity. The book moves on to various aspects of querying and modifying data, in Chapter 2 through Chapter 8, then to a discussion of concurrency and transactions in Chapter 9, and finally provides an overview of programmable objects in Chapter 10. The following section lists the chapter titles along with a short description:

Chapter 1, provides a theoretical background about SQL, set theory, and predicate logic; examines the relational model and more; describes SQL Server’s architecture; and explains how to create tables and define data integrity.

Chapter 2, covers various aspects of querying a single table using the SELECT statement.

Chapter 3, covers querying multiple tables using joins, including cross joins, inner joins, and outer joins.

Chapter 4, covers queries within queries, otherwise known as subqueries.

Chapter 5, covers derived tables, CTEs, views, inline table-valued functions, and the APPLY operator.

Chapter 6, covers the set operations UNION, INTERSECT, and EXCEPT.

Chapter 7, covers data-rotation techniques and working with grouping sets.

Chapter 8, covers inserting, updating, deleting, and merging data.

Chapter 9, covers concurrency of user connections that work with the same data simultaneously; it covers concepts including transactions, locks, blocking, isolation levels, and deadlocks.

Chapter 10, provides an overview to the T-SQL programming capabilities in SQL Server.

The book also provides an appendix, "Appendix A," to help you set up your environment, download the book’s source code, install the sample database TSQLFundamentals2008, start writing code against SQL Server, and learn how to get help by working with SQL Server Books Online.

P2.3. Companion Content

This book features a companion Web site that makes available to you all the code used in the book, the errata, additional resources, and more. The companion Web site is Please refer to Appendix A, for details about the source code.

P2.4. Hardware and Software Requirements

In Appendix A, I explain which editions of SQL Server 2008 you can use to work with the code samples included with this book. Each edition of SQL Server may have different hardware and software requirements, and those requirements are well-documented in SQL Server Books Online under "Section P2.4." Appendix A also explains how to work with SQL Server Books Online.

P2.5. Find Additional Content Online

For more great information from Microsoft Press, visit the new Microsoft Press Online sites—your one-stop online resource for access to updates, sample chapters, articles, scripts, and e-books related to our industry-leading Microsoft Press titles. Check out the following sites: and

P2.6. Support for This Book

Every effort has been made to ensure the accuracy of this book and the contents of the companion Web site. As corrections or changes are collected, they will be added to a Microsoft Knowledge Base article.

Microsoft Press provides support for books at the following Web site:

P2.6.1. Questions and Comments

If you have comments, questions, or ideas regarding the book, or questions that are not answered by visiting the sites above, please send them to me via e-mail at:

Or via postal mail at:

Microsoft Press
Attn: Microsoft SQL Server 2008 T-SQL Fundamentals Editor
One Microsoft Way
Redmond, WA 98052-6399

Please note that Microsoft software product support is not offered through the above addresses.

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint