MANNING MVP C ONTRIBUTORS John Baird ● Bob Beauchemin ● Itzik Ben-Gan ● Glenn Berry ● Aaron Bertrand ● Phil Brammer ● Robert C. Cain ● Michael Coles ● John Paul Cook ● Hilary Cotter ● Louis Davidson ● Christopher Fairbairn ● Rob Farley ● Denis Gobo ● Bill Graziano ● Dan Guzman ● Paul Ibison ● Tibor Karaszi ● Kathi Kellenberger ● Don Kiely ● Kevin Kline ● Hugo Kornelis ● Alex Kuznetsov ● Matija Lah ● Cristian Lefter ● Andy Leonard ● Greg Linwood ● Bruce Loehle-Conger ● Brad McGehee ● Paul Nielsen ● Pawel Potasinski ● Matthew Roche ● Dejan Sarka ● Edwin Sarmiento ● Gail Shaw ● Linchi Shea ● Richard Siddaway ● Jasper Smith ● Erland Sommarskog ● Scott Stauffer ● Tom van Stiphout ● Gert-Jan Strik ● Ron Talmage ● William R. Vaughn ● Joe Webb ● John Welch ● Erin Welker ● Allen White DEEP DIVES E DITED BY Paul Nielsen Kalen Delaney Greg Low Adam Machanic Paul S. Randal Kimberly L. Tripp Author royalties go to support War Child International Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com SQL Server MVP Deep Dives Licensed to Kerri Ross <pedbro@gmail.com> Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Licensed to Kerri Ross <pedbro@gmail.com> Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com SQL Server MVP Deep Dives Edited by Paul Nielsen Kalen Delaney Greg Low Adam Machanic Paul S. Randal Kimberly L. Tripp MANNING Greenwich (74° w. long.) Licensed to Kerri Ross <pedbro@gmail.com> Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. Sound View Court 3B Greenwich, CT 06830 Email: orders@manning.com ©2010 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Development editor: Jeff Bleiel Manning Publications Co. Lead copyeditor: Andy Carroll Sound View Court 3B Typesetter: Dottie Marsico Greenwich, CT 06830 Cover designer: Marija Tudor ISBN 978-1-935182-04-7 Printed in the United States of America 12345678910–MAL–141312111009 Licensed to Kerri Ross <pedbro@gmail.com> Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com v MVP contributors and their chapters John Baird 23 Bob Beauchemin 15 Itzik Ben-Gan 5 Glenn Berry 34, 47 Aaron Bertrand 29, 53 Phil Brammer 58 Robert C. Cain 13 Michael Coles 10, 11 John Paul Cook 39 Hilary Cotter 37 Louis Davidson 1, 2 Christopher Fairbairn 22 Rob Farley 7, 40 Denis Gobo 8, 20 Bill Graziano 6 Dan Guzman 32 Paul Ibison 36 Tibor Karaszi 25 Kathi Kellenberger 9 Don Kiely 16 Kevin Kline 45 Hugo Kornelis 3, 4 Alex Kuznetsov 41 Matija Lah 12 Cristian Lefter 21, 49 Andy Leonard 59 Greg Linwood 33 Bruce Loehle-Conger 52 Brad McGehee 24, 43 Paul Nielsen 1 Pawel Potasinski 19 Matthew Roche 57 Dejan Sarka 54 Edwin Sarmiento 35 Gail Shaw 42 Linchi Shea 48 Richard Siddaway 26 Jasper Smith 28 Erland Sommarskog 17 Scott Stauffer 38 Tom van Stiphout 14 Gert-Jan Strik 46 Ron Talmage 31 William R. Vaughn 18, 51 Joe Webb 30, 44 John Welch 56 Erin Welker 55 Allen White 27 Technical Editor Rod Colledge Licensed to Kerri Ross <pedbro@gmail.com> Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Licensed to Kerri Ross <pedbro@gmail.com> Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com To all children traumatized by the horrors of war and War Child’s efforts to help children be children again Licensed to Kerri Ross <pedbro@gmail.com> Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Licensed to Kerri Ross <pedbro@gmail.com> Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com ix brief contents PART 1DATABASE DESIGN AND ARCHITECTURE 1 1 Louis and Paul’s 10 key relational database design ideas 3 2 SQL Server tools for maintaining data integrity 11 3 Finding functional dependencies 28 PART 2DATABASE DEVELOPMENT 41 4 Set-based iteration, the third alternative 43 5 Gaps and islands 59 6 Error handling in SQL Server and applications 73 7 Pulling apart the FROM clause 86 8 What makes a bulk insert a minimally logged operation? 102 9 Avoiding three common query mistakes 111 10 Introduction to XQuery on SQL Server 119 11 SQL Server XML frequently asked questions 133 12 Using XML to transport relational data 150 13 Full-text searching 176 14 Simil: an algorithm to look for similar strings 200 15 LINQ to SQL and ADO.NET Entity Framework 210 16 Table-valued parameters 221 17 Build your own index 234 Licensed to Kerri Ross <pedbro@gmail.com> Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com [...]... to your SQL server ■ ■ ■ ■ Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Licensed to Kerri Ross CON TEN TS xxviii Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com instance 564 Using SQL Server 2008 transparent data encryption 564 Leaving auto create statistics and auto update statistics on 564 Verifying CHECKSUM for SQL Server. .. what’s causing it Finding I/O pressure in SQL Server 594 SQL Server memory pressure 597 SQL Server index usage 600 Detecting blocking in SQL Server 603 Summary 604 48 Query performance and disk I/O counters 592 606 LINCHI SHEA Expensive I/Os and very expensive I/Os 606 Disk performance counters 607 Random or sequential I/Os and disk performance counters 608 SQL Server operations and I/O sizes 610 How... VAUGHN What is SQL Server? 255 Understanding the SQL Server Browser service Diagnosing a connectivity problem 257 256 Testing for network availability 257 Managing the SQL Server instance state 258 Finding visible SQL Server instances 259 ■ ■ What is a connection? 261 To connect or not to connect 263 Connection management 264 Connection strategies 265 Establishing a connection 266 The server key 268... Data access 346 ■ Administration 347 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Licensed to Kerri Ross CON TEN TS xxii Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com PowerShell with SQL Server 2008 348 SQLPS Summary 27 348 ■ Provider 349 Cmdlets 350 351 Automating SQL Server Management using SMO 353 ALLEN WHITE Loading required... Incremental loads using T -SQL and SSIS 750 660 709 726 743 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Licensed to Kerri Ross Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Licensed to Kerri Ross Simpo PDF Merge and Split Unregistered... islands solutions 71 ■ ■ Summary 6 71 Error handling in SQL Server and applications 73 BILL GRAZIANO Handling errors inside SQL Server 73 Returning information about the error 74 Generate your own errors using RAISERROR 76 Nesting TRY CATCH blocks 77 TRY CATCH and transactions 79 ■ ■ ■ Handling SQL Server errors on the client 80 Handling SQL Server messages on the client Summary 7 82 84 Pulling apart... PowerShell in SQL Server 27 Automating SQL Server Management using SMO 28 Practical auditing in SQL Server 2008 365 29 My favorite DMVs, and why 30 Reusing space in a table 31 Some practical issues in table partitioning 413 32 Partitioning for manageability (and maybe performance) 33 Efficient backups without indexes 34 Using database mirroring to become a superhero! 35 The poor man’s SQL Server log shipping... - http://www.simpopdf.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Licensed to Kerri Ross Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com preface Each year Microsoft invites all the MVPs from every technology and country to Redmond for an MVP Summit—all top secret—“don’t tweet what you see!” During the MVP Summit, each product... in SQL Server 2008 365 JASPER SMITH Overview of audit infrastructure 365 Server audit objects 365 Server audit specification objects Database audit specification objects 366 ■ Server audits 366 366 Configuring the Windows Security Log target 367 Creating a server audit using the Windows Security Log target 368 Creating a security audit using the Windows Application Log target 370 Configuring a server. .. task 336 Execute SQL Server Agent job task 338 Back up database task 338 Maintenance cleanup task 340 Select reporting options 341 Execute T -SQL statement task 341 ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ Executing and monitoring the plan Summary 343 26 PowerShell in SQL Server 342 344 RICHARD SIDDAWAY PowerShell overview PowerShell features 344 344 ■ PowerShell issues and solutions 345 PowerShell with SQL Server 2000 and . <pedbro@gmail.com> Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com SQL Server MVP Deep Dives Edited by Paul. purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com SQL Server MVP Deep Dives Licensed to Kerri Ross <pedbro@gmail.com> Please. with maintenance plans 330 26 PowerShell in SQL Server 344 27 Automating SQL Server Management using SMO 353 28 Practical auditing in SQL Server 2008 365 29 My favorite DMVs, and why