Home > Store

Developer's Guide to SQL Server 2005, A

Register your product to gain access to bonus material or receive a coupon.

Developer's Guide to SQL Server 2005, A


  • Sorry, this book is no longer in print.
Not for Sale

Audio & Video


Inside the book with Bob Beauchemin: Video Podcast

In this interview Bob Beauchemin describes who should read his book and what the developer will find inside. Listen to highlights of the most useful features of SQL Server 2005!


  • Copyright 2006
  • Edition: 1st
  • Book
  • ISBN-10: 0-321-38218-8
  • ISBN-13: 978-0-321-38218-4

"I come from a T-SQL background, so when I first laid my eyes on SQL Server 2005, I was shocked--and then, I was scared! I didn't have a CLR or XML background and suddenly had an urgent need to learn it. SQL Server 2005 is too big of a release to learn from the books online. Fortunately, now there is a book for developers who need to go from SQL Server 2000 to SQL Server 2005 and to do it as painlessly as possible. Basically, it's one-stop shopping for serious developers who have to get up to speed quickly. I'll keep this one on my desk--not on my bookshelf. Well done, Bob and Dan!"

--Dr. Tom Moreau

SQL Server MVP and Monthly Columnist

SQL Server Professional, Brockman Moreau Consulting Inc.

"A SQL book truly for developers, from two authorities on the subject. I'll be turning to this book first when I need to understand a component of SQL Server 2005."

--Matt Milner



"An excellent book for those of us who need to get up to speed on what's new in SQL Server 2005. The authors made sure this book includes the final information for the release version of the product. Most other books out now are based on beta versions. It covers key areas from XML and SQLCLR to Notification Services. Although the wide variety of information is great, my favorite part was the advice given on when to use what, and how performance is affected."

--Laura Blood

Senior Software Developer

Blue Note Computing, Inc.

"SQL Server 2005 is a massive release with a large number of new features. Many of these features were designed to make SQL Server a great application development platform. This book provides comprehensive information about the SQL Server features of most interest to application developers. The lucid text and wealth of examples will give a developer a clear understanding of how to use SQL Server 2005 to a whole new class of database applications. It should be on every SQL Server developer's bookshelf."

--Roger Wolter

Solutions Architect

Microsoft Corporation

"While there will be a lot of good books on SQL Server 2005 development, when people refer to the 'bible,' they'll be talking about this book."

--Dr. Greg Low

Senior Consultant

Readify Pty Ltd

"SQL Server 2005 is loaded with new features and getting a good overview is essential to understand how you can benefit from SQL Server 2005's features as a developer. Bob and Dan's book goes beyond enumerating the new SQL Server 2005 features, and will provide you with lots of good examples. They did a good job striking a balance between overview and substance."

--Michiel Wories

Senior Program Manager, SQL Server

Microsoft Corporation

Few technologies have been as eagerly anticipated as Microsoft SQL Server 2005. Now, two SQL Server insiders deliver the definitive hands-on guide--accurate, comprehensive, and packed with examples. A Developer's Guide to SQL Server 2005 starts where Microsoft's documentation, white papers, and Web articles leave off, showing developers how to take full advantage of SQL Server 2005's key innovations. It draws on exceptional cooperation from Microsoft's SQL Server developers and the authors' extensive access to SQL Server 2005 since its earliest alpha releases.

You'll find practical explanations of the new SQL Server 2005 data model, built-in .NET hosting, improved programmability, SQL:1999 compliance, and much more. Virtually every key concept is illuminated via sample code that has been fully updated for and tested with the shipping version of the product.

Key coverage includes

  • Using SQL Server 2005 as a .NET runtime host: extending the server while enhancing security, reliability, and performance
  • Writing procedures, functions, triggers, and types in .NET languages
  • Exploiting enhancements to T-SQL for robust error-handling, efficient queries, and improved syntax
  • Effectively using the XML data type and XML queries
  • Implementing native SQL Server 2005 Web Services
  • Writing efficient, robust clients for SQL Server 2005 using ADO.NET, classic ADO, and other APIs
  • Taking full advantage of user-defined types (UDTs), query notifications, promotable transactions, and multiple active result sets (MARS)
  • Using SQL Management Objects (SMO), SQL Service Broker, and SQL Server Notification Services to build integrated applications

Sample Content

Online Sample Chapter

In-Process Data Access in SQL Server 2005

Downloadable Sample Chapter

Download the Sample Chapter related to this title.

Table of Contents

Figures xxv

Tables xxxix

Foreword by Roger Wolter xliii

Foreword by Gert E. R. Drapers xlv

Preface xlix

Acknowledgments lv

About the Authors lvii

Chapter 1: Introduction 1

The .NET Framework and the Microsoft Platform 1

The .NET Framework's Effects on SQL Server 3

The SQL:1999 Standard: Extending the Relational Model 8

User-Defined Types and SQL Server 11

XML: Data and Document Storage 14

Web Services: XML As a Marshaling Format 20

Client Access . . . And Then There Are Clients 22

Extending SQL Server into the Platform: Service Broker and Notification Services 24

Where Are We? 26

Chapter 2: Hosting the Runtime: SQL Server As a Runtime Host 27

Why Care How Hosting Works? 27

What Is a .NET Framework Runtime Host? 29

SQL Server As a Runtime Host 31

Loading the Runtime: Processes and AppDomains 40

Safe Code: How the Runtime Makes It Safer to Run "Foreign" Code 43

Where the Code Lives: Storing .NET Framework Assemblies (CREATE ASSEMBLY) 46

Assembly Dependencies: When Your Assemblies Use Other Assemblies 49

Assemblies and SQL Schemas: Who Owns Assemblies (Information Schema) 51

Maintaining User Assemblies (ALTER ASSEMBLY, DROP ASSEMBLY) 55

Specification Compliance 58

Conclusions 60

Where Are We? 60

Chapter 3: Procedures and Functions in .NET CLR Languages 61

Extending SQL Server 61

CLR Extension Basics 63

CLR Extension Details 74

System.Data.SqlTypes 77

Parameters and Return Value 93

User-Defined Functions 93

Table-Valued Functions 99

Stored Procedures 106

Triggers 109

Where Are We? 110

Chapter 4: In-Process Data Access 111

Programming with SqlClient 111

Context: The SqlContext Class 115

Connections 118

Commands: Making Things Happen 121

Obtaining Results 124

Transactions 128

Pipe 135

Creating and Sending New Rowsets 137

Using the WindowsIdentity 139

Calling a Web Service from SQLCLR 140

Exception Handling 143

SqlTriggerContext 149

SqlClient Classes That You Can't Use on the Server 150

Where Are We? 151

Chapter 5: User-Defined Types and Aggregates 153

Why Do We Need User-Defined Types? 153

Overview of User-Defined Types 154

Creating a User-Defined Type 157

Where Are We? 217

Chapter 6: Security 219

New Security Features in SQL Server 2005 219

Optional Features Are Turned Off by Default 221

A Quick Review of SQL Server Security Concepts with Enhancements 224

SQL Server Password Policies and Credentials 235

Encryption Keys and Built-In Encryption Functions 238

Encryption Functions 242

Separation of Users and Schemas 248

Synonyms 252

Specifying Execution Context for Procedural Code 253

Code Signing 259

SQL Server Permissions and SQLCLR Objects 261

Assembly Permissions: Who Can Catalog and Use an Assembly? 262

What .NET Framework Code Can Do from within SQL Server: Safety Levels 268

Where Are We? 275

Chapter 7: SQL Engine Enhancements 277

Improvements to the SQL Engine 277

SNAPSHOT Isolation 278

Data Definition Language Triggers 289

Event Notifications 294

Large Value Data Types 298

Loading Data with the New BULK Provider 301

Statement-Level Recompilation 301

Query Hints, Plan Guides, and Plan Forcing 303

Where Are We? 309

Chapter 8: T-SQL Language Enhancements 311

Improvements to Transact-SQL 311

Error Handling 312


TOP 329



APPLY Operators 340

Common Table Expressions 343

Recursive Queries 351

PIVOT and UNPIVOT Operators 359

Ranking and Partitioning 366


Where Are We? 381

Chapter 9: XML in the Database: The XML Data Type 383

The XML Data Type 383

Using XML Data Type in Tables 384

Using XML Data Variables and Parameters 390

Typed and Untyped XML: Cataloguing and Using XML SCHEMA COLLECTIONs 392

Creating an Index on an XML Column 401

XML Type Functions 402

SELECT . . . FOR XML Enhancements 403

Mapping SQL and XML Data Types 414

OpenXML Enhancements 418 Loading XML into the Database from Files 420

ANSI SQL Standard Compliance 422

Where Are We? 426

Chapter 10: XML Query Languages: XQuery and XPath 429

What Is XQuery? 429

An Introduction to XQuery 431

Comparing and Contrasting XQuery and SQL 446

Using XQuery with the XML Data Type 449

XQuery Functions Supported by SQL Server 463

XQuery Operators Supported by SQL Server 464

XML DML: Updating XML Columns 468

Special Considerations When Using XQuery Inside SQL Server 475

Where Are We? 480

Chapter 11: SQL Server Service Broker 481

Messaging Applications 481

Processing Messages 494

Business Transactions 499

Where Are We? 559

Chapter 12: SQL Server As a Platform for Web Services 561

Mixing Databases and Web Services 561

Where Are We? 640

Chapter 13: SQL Server 2005 and Clients 641

SQL Native Client 641

New Data Types and Data Type Compatibility Mode 645

User-Defined Types and Relational Data Access APIs 646

Using .NET Framework UDTs in ADO.NET 647

Fetching UDT Data from a DataReader 648

Using .NET Framework UDTs in ODBC, OLE DB, and ADO Clients 654

Supporting the XML Data Type on the Client 657

Supporting the Large Value Data Types on the Client 667

Query Notification Support 670

Multiple Active Resultsets 689

New Transaction and Isolation Features in ADO.NET 695

Changes Related to SQL Server 2005 Login 699

Comparing the Client and Server Model for Stored Procedures 703

Where Are We? 704

Chapter 14: ADO.NET 2.0 and SqlClient 705

Generic Coding with the ADO.NET 2.0 Base Classes and Factories 705

Provider Factories 709

Specifying Configuration Information 712

Enumerating Data Sources and Building Connection Strings 714

Other Generic Coding Considerations 717

Schemas in ADO.NET 2.0 719

Tracing Data Access 731

Asynchronous Support 743

Bulk Import in SqlClient 749

Client Statistics 752

.NET Framework DataSet and SqlDataAdapter Enhancements 753

Where Are We? 758

Chapter 15: SQL Server Management Objects 761

Introduction 761

Object Model 769

SMO Projects 772

Connections 778

Server 787

SMO Objects 790

Create, Alter, and Drop 802

Scripts 807

Configuration Management 815

Where Are We? 818

Chapter 16: Notification Services 819

What Is SQL Server Notification Services? 819

Notification Applications 821

Components of SQL Server Notification Services 824

Notification Applications Design Patterns 828

Notification Services Delivery Features 829

Terms Used in Notification Services 829

Designing, Coding, and Generating a Notification Services Application 831

A Sample Notification Application 833

Instance and Application Configuration Files 834

Events 846

Subscribers and Subscriptions 858

Notifications 867

Distributor and Formatters 871

Delivery 873

Where Are We? 878

Chapter 17: Wrap-Up: Service-Oriented Database Applications 879

Lots of New Features: How to Use Them 879

Data Models, Programming, and SQL Server 880

Any Functionality at Any Tier 881

What Are the Best Practices? 882

Toward a Service-Oriented Database Architecture 891

The Database As Part of the Platform 894

Appendix A .NET Framework 101 897

The Common Language Runtime 897

Assemblies and Modules 901

The CLR Type System 905

Members of Types 914

Memory Management 918

Appendix B SQL Server Management Studio 923

Introduction 923

Solutions and Projects 924

Templates 937

Object Explorer 944

Appendix C Visual Studio 2005 Integration: SQL Server Projects 949

Visual Studio 2005 949

References 963

Index 965


Download the Foreword related to this title.


Download the Index file related to this title.


Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020