Reader's Choice PDF Series, Mastering Microsoft SQL Server: Professional-
grade techniques for developers (ISBN-1-58205-124-0) is published by. Element
K ...
Mastering Microsoft SQL Server : Professional-grade techniques for developers ®
™
Table of Contents: Support fuzzy comparisons in your database queries ........................................................... 4 Access SQL Server 2000 through XML and HTTP ................................................................. 8 Solve complex data relationship problems with recursive triggers.................................. 13 Build a database comparison utility with Visual Basic and SQL DMO ............................. 16 Broaden SQL Server’s capabilities with extended stored procedures ............................ 21 Tap into Enterprise Manager with the SQLNamespace library .......................................... 26
Additional Information: Reader’s Choice PDF Series, Mastering Microsoft SQL Server: Professionalgrade techniques for developers (ISBN-1-58205-124-0) is published by Element K Journals, a division of Element K Press, 500 Canal View Blvd., Rochester, N.Y., 14623.
Customer Relations U.S. toll-free . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .(800) 223-8720 Canada toll-free . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .(877) 203-5248 Outside the U.S. and Canada . . . . . . . . . . . . . . . . . . . . . .(585) 240-7301 Customer Relations fax . . . . . . . . . . . . . . . . . . . . . . . . . . .(585) 292-4392
Editorial Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Jason Fisher Associate Publisher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Michelle Rogers Managing Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Craig Watkins Copy Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Leesa A. Israel Cover Design and Content Designer . . . . . . . . . . . . . . . Melissa Ribaudo Graphic Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Melissa Ribaudo
Copyright Please be aware of our copyright policy. Questions or requests for permission to copy or republish any content may be directed to:
[email protected]. © 2004 Element K Journals, a division of Element K Press LLC (“Element K”). All rights reserved except for the right to view this PDF using a Web browser and to make private, noncommercial use hereof. PDF content may be printed by the purchaser, but may not be duplicated and distributed. Element K and the Element K logo are trademarks of Element K LLC. The content published in this PDF (“Content”) is the property of Element K or its affiliates or third party licensors and is protected by copyright law in the U.S. and elsewhere. This means that the right to copy and publish the Content is reserved. Content may not be copied in whole or in part or further distributed in any form or medium without the express written permission of Element K. All product names or services identified throughout this PDF are trademarks or registered trademarks of their respective companies.
Price
Multi-user options are available
Price . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . $14.95
To request information about multi-user options please call Brian McKeon at (585) 292-4363.
Our Canadian GST # is R140496720. Our CPM # is 40031405. Our QST # is 1018491237.
Contact us at www.elementkjournals.com or 1.800.223.8720
© 2004 Element K Journals
2
A Note from our Publisher: Dear Microsoft SQL Server Enthusiast, Thank you for choosing Element K Journals, the leading provider of computer technology journals and professional development products, as your comprehensive, innovative, and timely information resource. Since the company’s inception more than 20 years ago, publishing best-selling software support books has evolved into producing a complete line of digital and print products designed to complement every skill level and provide solutions to the challenges you face every day. Throughout this period of growth, we have maintained our focus on providing you with the highest quality content, in an easy-to-read format, through the best mediums available. That’s why we’ve created the new Reader’s Choice PDF Series. This series of downloadable reports contains a best-of selection of our most-requested articles covering hot topics in technology and professional development. You can have instant access to the information you need— right here, right now! In addition to our Reader’s Choice PDF Series, Element K Journals produces nearly 40 monthly how-to journals, a family of CD-ROM products, Quick Skills Kits, Quick Reference Guides, Quick Reference Cards, special reports, tip booklets, and weekly email tips. For more information regarding Element K Journals and a complete product listing, please visit our Web site at www.elementkjournals.com. Sincerely,
Doreen M. Bieryla Publisher, Element K Journals
A Note from the Editor: Downsizing. Layoffs. Outsourcing. No matter what they call it, it means one thing: your developer skills need to be a step above the rest. Whether it’s carving out complex data relationships, or pushing SQL Server’s functionality to its limits—in today’s competitive IT job market, database developers need as much of an edge as they can get. To stay ahead of the pack, though, you have to go beyond the manuals. That’s what readers of SQL Server Solutions have told us, and that’s why I’ve pulled together a few of the solutions and techniques they’ve found most useful. I hope you find them as helpful as my readers have.
Editor Bio: Jason Fisher
Jason holds MCP and BCIP certifications in several development technologies. He’s a consultant, freelance writer, and editor whose work has been seen in numerous journals and magazines, including Visual Studio Magazine (formerly Visual Basic Programmer’s Journal), MSDN Magazine, Windows Developer Magazine (formerly Windows Developer’s Journal), and many others. Jason is currently the editor of Element K Journals’ SQL Server Solutions journal. When not writing or developing, he can usually be found napping in the sunny spot on the floor near the window.
Contact us at www.elementkjournals.com or 1.800.223.8720
© 2004 Element K Journals
3
Support fuzzy comparisons in your database queries by Jason Fisher, MCP, BCIP Application: Microsoft SQL Server 6.5/7.0/2000 Operating Systems: Microsoft Windows NT/2000/XP Most database applications perform very narrow queries, in which the term being searched for must match the term in the records being searched precisely. But a great many database applications would benefit from the ability to support “fuzzier” comparisons. For example, suppose you’re developing a customer service application for a call center. Customers telephone for service from your personnel, and when these customers provide their name, your data-driven application should be smart enough to find them quickly even when you may not have the exact spelling of the customer’s name. Fortunately, Microsoft SQL Server provides a relatively easy way to implement this kind of fuzzy search using the SOUNDEX and DIFFERENCE functions.
Warm fuzzy
In this article, we’ll cover the basics of fuzzy queries in T-SQL. We’ll begin by explaining the origins of the Soundex algorithm, along with how it works. Then, we’ll introduce two important T-SQL functions, SOUNDEX and DIFFERENCE, both of which are based on SQL Server’s built-in implementation of Soundex. Finally, we’ll take you through the process of implementing a sample Web application that supports flexible fuzzy searches. By the time we’re finished, you’ll be ready to augment your own data-driven applications with these techniques.
What is Soundex?
The Soundex algorithm was developed in the 1920s by the United States Bureau of Archives to facilitate census-taking. This was a period of heavy immigration into the United States. The increasing number of unfamiliar ethnic names necessitated a technique for categorizing these names to ensure they were accurately recorded. The earliest use of Soundex was a manual process, whereby census-takers converted a name into its four-character Soundex representation, then recorded it on paper for filing. Since its inception, Soundex and variations on the original Soundex algorithm have been used in numerous industries. For example, the airline reservations industry uses Soundex to assist its personnel in pronouncing passenger’s names. Soundex is also frequently used in genealogy to account for alternate spellings of family names. And many of today’s Web sites use some form of Soundex to facilitate fuzzy content searches. This is precisely what we’ll be doing a little later on in our sample application.
Do you hear what I hear?
So how exactly does Soundex work? It’s really quite a simple algorithm when you break it down into steps. Basically, here’s the process: • The first letter of the word to be encoded is always preserved as the first letter of the Soundex code.
Table A: Soundex consonantal mappings Consonant Soundex value B, F, P, V C, G, K, J, Q, S, X, Z D, T L M, N R
Contact us at www.elementkjournals.com or 1.800.223.8720
1 2 3 4 5 6
Figure A: Query Analyzer allows us to confirm the Soundex code for any character data we like.
© 2004 Element K Journals
4