The Best of Sqlservercentral.Com Vol. 3
Total Page:16
File Type:pdf, Size:1020Kb
The Best of SQLServerCentral.com — 3 Vol. In April 2001 six geeks banded together to form a more perfect site. Three years and 140,000+ members later, SQLServerCentral.com is one of the premier SQL Server communities in the world. We’ve got over 1,000 articles, 100s of scripts and FAQs, everything you would need as a SQL Server DBA or developer, and all The Best of at a great price — free. This book contains the best material published on the site from 2004. It’s a SQLServerCentral.com variety of topics from administration to advanced querying. XML to DTS, security to performance tuning. And of course, the famous White Board, Flip Chart, or Notepad debate. Vol. 3 So why print a book containing material you can get for free? Take a minute, read the introduction and find out! Essays and Ideas from the SQL Server Community Ameet Phadnis, Amit Jethra, Andre Vigneau, Andy Warren, Anthony Bressi, Ashish Kaushal, Brian Kelley, Brian Knight, Bruce Szabo, Chris Cathers, Chris Kempster, Christoffer Hedgate, Dale Elizabeth Corey, David Poole, Denny Figuerres, Dinesh Asanka, Dinesh Priyankara, Don Peterson, Eli Leiba, G Vijayakumar, Goce Smilevski, Haidong Ji, James Luetkehoelter, James Travis, Jeff Moden, Jeffrey Yao, Joe Sack, Jon Reade, Jon Winer, Joseph Gama, Keith Henry, Kevin O’Donovan, Krishna Sonti, Leo Peyasakhovich, Mark Nash, Nicholas Cain, Patryk Nowakowski, Paul Ibison, Randy Dyess, Ramesh Gummadi, Ramunas Balukonis, Robert Marda, Robert Pearl, Robin Back, Sanket Naik, Santveer Singh, Sharad Nandwani, Shiv Kumar, Sotiris Filippidis, Stefan Popovski, Stephen Lasham, Steve Jones, Sureshkumar Ramakrishnan, Vinod Kumar, Wayne Fillis, Wes Brown Shelving: Database/SQL Server $19.95 USA The Best of SQLServerCentral.com – Vol. 3 The Best of SQLServerCentral.com – Vol. 3 Ameet Phadnis Amit Jethra Andre Vigneau Andy Warren Anthony Bressi Ashish Kaushal Brian Kelley Brian Knight Bruce Szabo Chad Miller Chris Cathers Chris Kempster Christoffer Hedgate Dale Elizabeth Corey David Poole Denny Figuerres Dinesh Asanka Dinesh Priyankara Don Peterson Eli Leiba G Vijayakumar Goce Smilevski Haidong Ji James Luetkehoelter James Travis Jeff Moden Jeffrey Yao Joe Sack Jon Reade Jon Winer Kevin O'Donovan Krishna Sonti Leo Peyasakhovich Mark Nash Nicholas Cain Paul Ibison Patryk Nowakowski Ramesh Gummadi Ramunas Balukonis Robert Marda Robert Pearl Robin Back Sanket Naik Santveer Singh Shiv Kumar Sotiris Filippidis Stefan Popovski Steve Jones Sureshkumar Ramakrishnan Vinod Kumar Wayne Fillis Wes Brown 1 The Best of SQLServerCentral.com – Vol. 3 The Central Publishing Group 3186 Michaels Ct Green Cove Springs, FL 32043 U.S.A Copyright Notice Copyright 2005 by The Central Publishing Group. All rights reserved. Except as permitted under the Copyright Act of 1976, no part of this publication may be reproduced under the Copyright Act of 1976. No part of this publication may be reproduced in any form or by any means or by a database retrieval system without the prior written consent of The Central Publishing Group. The publication is intended for the audience of the purchaser of the book. This publication cannot be reproduced for the use of any other person other than the purchaser. Authors of the material contained in this book retain copyright to their respective works. Disclaimer The Central Publishing Group, SQLServerCentral.com, and the authors of the articles contained in this book are not liable for any problems resulting from the use of techniques, source code, or compiled executables referenced in this book. Users should review all procedures carefully, test first on a non-production server, and always have good backup before using on a production server. Trademarks Microsoft, SQL Server, Windows, and Visual Basic are registered trademarks of Microsoft Corporation, Inc. Oracle is a trademark of Oracle Corporation. Editors Steve Jones and Andy Warren Cover Art Sylvia Peretz of PeretzDesign.com 2 The Best of SQLServerCentral.com – Vol. 3 The Best of SQLServerCentral.com – Vol. 3 Table of Contents Introduction 5 Administration 6 A Bit About 64-bit Robert Pearl 7 An Introduction To Linked Servers Krishna Sonti 9 Creating a System Stored Procedure Robert Marda 12 Distributed Backup Checking Kevin O'Donovan 13 Finding Objects Owned by non-DBO Users Santveer Singh 16 Four of a Kind - Backup Software Shootout Wes Brown 17 Four of a Kind - Backup Software Shootout Part 2 Wes Brown 21 How To Find SQL Server Objects Ashish Kaushal 23 Monitoring Drive and Database Free Space Mark Nash 27 Moving System Databases - A Checklist Christoffer Hedgate 30 Scheduled MS Cluster Failovers using Automation Server Objects Anthony Bressi 33 Top Ten Features of Enterprise Manager Dale Elizabeth Corey 35 Tracing Deadlocks Shiv Kumar 43 T-SQL and Programming 46 ADO.NET – A Data Access Layer Patryk Nowakowski 47 An Efficient Set-based Solution for Islands and Gaps Goce Smilevski 52 Be Prepared! Stefan Popovski 57 Calculating Work Days Jeff Moden 60 Capturing The Error Description In A Stored Procedure Amit Jethva 63 Conditional Statements in WHERE Clauses Sotiris Filippidis 64 Deleting Duplicate Records Sureshkumar Ramakrishnan 66 Extract a String From Between Two Delimiting Characters Stephen Lasham 67 Joins Clarified Sanket Naik 69 Manipulating And Using DateTime Data Robert Marda 70 Null Functions (Arent those Meetings?) Dinesh Priyankara 73 Searching the File System Chris Cathers 75 Unique Identifier: Usage and Limitations Sharad Nandwani 77 Versioning Andre Vigneau 78 Disaster Recovery 80 From the Soapbox: Does Anyone Know What Disaster Recovery Is? James Luetkehoelter 81 Incident Response - The Framework Steve Jones 82 Incident Response - Responding to an Incident Steve Jones 85 Log Shipping vs. Replication Paul Ibison 89 Business Intelligence, Reporting Services, and ETL 92 Analysis About Analysis Services Ramunas Balukonis 93 3 The Best of SQLServerCentral.com – Vol. 3 A DTS Data Store Bruce Szabo 95 Data Migration : Step by Step Chris Kempster 99 Introduction to MDX Keith Henry 109 Reporting Services Part I: Overview, Architecture, and Installation James Luetkehoelter 114 Tutorial: Designing Your First Report in SQL Server Reporting Services Brian Knight 122 Tutorial: Adding Conditional Formatting into Reporting Services Brian Knight 125 Tutorial: Changing the Visibility of Objects in Reporting Services Brian Knight 127 Database Design 129 Lookup Table Madness Don Peterson 130 How to be a Good DBA - Strategy and Tactics Jeffrey Yao 132 An Introduction to Database Models Frank Kalis 134 Speed up Development on Backend and Middle Tier with SQL Scripts Ameet Phadnis 137 Stored Procedure vs Triggers G Vijayakumar 142 Performance 152 Analyzing Data Storage - Ten SHOWCONTIG Queries Joe Sack 153 Checking Your Database Fragmentation Level Nicholas Cain 156 Index Creation Guidelines Leo Peysakhovich 160 Indexing Strategies Ramesh Gummadi 163 Security 166 How to Make Sure You Have Good Passwords Robin Back 167 Port Blocking, SQL Server, and the Internet Denny Figuerres 168 RC3 Encryption in a Stored Procedure Joseph Gama 169 SQL Server Security: Dealing with Anti-Virus Programs Brian Kelley 172 XML 176 An Alternative XML Solution Wayne Fillis 177 Changing Databases Using XML Dinesh Asanka 180 Handling Simple XML Using T-SQL Eli Leiba 183 Reduce Database RoundTrips Using XML Jon Winer 185 SQL Server 2005 190 Introduction to DTS in SQL Server 2005 Vinod Kumar 191 SQL Server 2005 DBCC Command Quick Reference Jon Reade 198 Yukon Passwords Randy Dyess 202 Everything Else 207 Becoming More Productive Haidong Ji 208 Hidden Dangers! James Travis 209 Is all code really code? One question from an interview Andy Warren 211 The Danger of Hiring Stars David Poole 212 Think like a DBA Andy Warren 215 About the Authors 217 4 The Best of SQLServerCentral.com – Vol. 3 Introduction Welcome to The Best of SQLServerCentral.com – Vol. 3! Once again SQLServerCentral.com had another fantastic year and we decided to reprint some of the best articles, the most popular, and the most read in dead tree format. We wanted to give all our authors a chance to see their names in print as well as give you an off-line resource that you can take with you wherever you may need it-most likely at your bedside to help you drop off at night :), for commutes, holding your coffee cup, whatever. This is our third volume and it's become an annual tradition. We would also like to thank everyone for their support both on the website as well as by purchasing this book. Your visits to the site, clicking through to advertisers, purchasing products, registering for PASS, all help us continue this community and provide you with a valuable resource that hopefully helps you learn, perform better at your job, and grow your career. We’d like to encourage all of you to submit an article in 2005! This is a community and we aren’t looking for the gurus only to contribute. We love hearing about the real world you all live in and deal with on a daily basis. We plan to get at least one article from each author and send you a couple copies of the book. Great for your bookshelf and they make a great Mother’s Day present. Once again, thanks so much for your support and we look forward to 2005. Andy Warren Brian Knight Steve Jones 5 The Best of SQLServerCentral.com – Vol. 3 Administration This is what we do: administer servers and databases. Everyone has their own set of tricks, tips, scripts tailored to the quirks of their own systems. We can each get sidetracked into dealing with our own systems and miss out on understanding some other sections of SQL Server that we don’t work with. Here’s a selection of articles to impart a little more information about the server, Autoclose, AWE, Traces and more. As we compile this 3rd edition, Microsoft SQL Server is a very mature product that is mostly being limited by its architecture as hardware continues to grow in power, loads increase, and many different stresses occur.