0% found this document useful (0 votes)
20 views

SQL Server 2000 Stored Procedures XML Programming 2nd Edition Dejan Sunderic instant download

The document provides information about the book 'SQL Server 2000 Stored Procedures & XML Programming, Second Edition' by Dejan Šunderic, including details on its content, author, and publisher. It includes links to download the book and other related titles in various formats. The book covers topics such as stored procedure design, debugging, and XML for database developers.

Uploaded by

zottisiarakg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

SQL Server 2000 Stored Procedures XML Programming 2nd Edition Dejan Sunderic instant download

The document provides information about the book 'SQL Server 2000 Stored Procedures & XML Programming, Second Edition' by Dejan Šunderic, including details on its content, author, and publisher. It includes links to download the book and other related titles in various formats. The book covers topics such as stored procedure design, debugging, and XML for database developers.

Uploaded by

zottisiarakg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

SQL Server 2000 Stored Procedures XML

Programming 2nd Edition Dejan Sunderic pdf


download

https://ebookname.com/product/sql-server-2000-stored-procedures-
xml-programming-2nd-edition-dejan-sunderic/

Get Instant Ebook Downloads – Browse at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Programming Oracle Triggers and Stored Procedures 3rd


Edition Feng Yuan

https://ebookname.com/product/programming-oracle-triggers-and-
stored-procedures-3rd-edition-feng-yuan/

Pro SQL Server 2008 XML 1st Edition Michael Coles


(Auth.)

https://ebookname.com/product/pro-sql-server-2008-xml-1st-
edition-michael-coles-auth/

Professional SQL Server 2000 Data Warehousing with


Analysis Services 1st Edition Chris Graves

https://ebookname.com/product/professional-sql-server-2000-data-
warehousing-with-analysis-services-1st-edition-chris-graves/

Dealing with d4 Deviations 1st Edition John Cox

https://ebookname.com/product/dealing-with-d4-deviations-1st-
edition-john-cox/
Settlement and Urbanization in Early Islamic Palestine
7th 11th Centuries Texts and Archaeology Contrasted 1st
Edition Hagit Nol

https://ebookname.com/product/settlement-and-urbanization-in-
early-islamic-palestine-7th-11th-centuries-texts-and-archaeology-
contrasted-1st-edition-hagit-nol/

Stress Relief for Teachers The Coping Triangle 1st


Edition Claire Hayes

https://ebookname.com/product/stress-relief-for-teachers-the-
coping-triangle-1st-edition-claire-hayes/

Obstetrics Evidence Based Guidelines 1st Edition Carp


Howard

https://ebookname.com/product/obstetrics-evidence-based-
guidelines-1st-edition-carp-howard/

Patch Clamping An Introductory Guide to Patch Clamp


Electrophysiology 1st Edition Areles Molleman

https://ebookname.com/product/patch-clamping-an-introductory-
guide-to-patch-clamp-electrophysiology-1st-edition-areles-
molleman/

Religious Idiom and the African American Novel 1952


1998 1st Edition Tuire Valkeakari

https://ebookname.com/product/religious-idiom-and-the-african-
american-novel-1952-1998-1st-edition-tuire-valkeakari/
The McGraw Hill Guide Writing for College Writing for
Life 2nd edition Roen

https://ebookname.com/product/the-mcgraw-hill-guide-writing-for-
college-writing-for-life-2nd-edition-roen/
SQL Server 2000
TM

Stored Procedure
& XML Programming
Second Edition

Dejan Šunderic

McGraw-Hill/Osborne
New York Chicago San Francisco
Lisbon London Madrid Mexico City Milan
New Delhi San Juan Seoul Singapore Sydney Toronto
McGraw-Hill/Osborne
2100 Powell Street, 10th Floor
Emeryville, California 94608
U.S.A.

To arrange bulk purchase discounts for sales promotions, premiums, or fund-raisers, please contact
McGraw-Hill/Osborne at the above address. For information on translations or book distributors
outside the U.S.A., please see the International Contact Information page immediately following the
index of this book.

SQL Server™ 2000 Stored Procedure & XML Programming, Second Edition

Copyright © 2003 by The McGraw-Hill Companies. All rights reserved. Printed in the United States
of America. Except as permitted under the Copyright Act of 1976, no part of this publication may be
reproduced or distributed in any form or by any means, or stored in a database or retrieval system,
without the prior written permission of publisher, with the exception that the program listings may be
entered, stored, and executed in a computer system, but they may not be reproduced for publication.
1234567890 CUS CUS 019876543
ISBN 0-07-222896-2

Publisher Brandon A. Nordin


Vice President & Associate Publisher Scott Rogers
Acquisitions Editor Lisa McClain
Project Editor Janet Walden
Acquisitions Coordinator Athena Honore
Technical Editor Deborah Bechtold
Development Editor Tom Woodhead
Copy Editor William McManus
Proofreader Laurie Stewart
Indexer Valerie Robbins
Computer Designers Carie Abrew, Tara A. Davis, Lucie Ericksen
Illustrators Lyssa Wald, Melinda Moore Lytle, Kathleen Fay Edwards
Series Designer Peter F. Hancik
Cover Series Designer Pattie Lee

This book was composed with Corel VENTURA™ Publisher.

Information has been obtained by McGraw-Hill/Osborne from sources believed to be reliable. However, because of the possibility
of human or mechanical error by our sources, McGraw-Hill/Osborne, or others, McGraw-Hill/Osborne does not guarantee the
accuracy, adequacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained
from the use of such information.
Writing a book isn’t easy, but living with someone
who is writing a book can be, at times, even harder.
I would like to thank my family for their patience,
understanding, and inspiration.

Acknowledgments
I wish to thank all the people who helped to make this book a reality,
in particular:

 Tom Woodhead, for straightening the winding course of my writings.


 Olga Baranova, who created several examples for Chapters 10, 11, and 15.
 Wendy Rinaldi and Lisa McClain, for the opportunity to do this project.
 Athena Honore and Janet Walden, for their patience, expertise, and
hard work.
 Deborah Bechtold, for her expertise and hard work beyond the call of duty.
About the Author
Dejan Šunderic is the principal consultant at Trigon Blue, Inc. (www.trigonblue.com).
He specializes in database and application development for Internet and
Windows platforms.
Projects that he has been involved with cover B2C and B2B e-commerce, financial,
document-management, mortgage, asset management, insurance, real-estate, IT
supply chain, process control, communication, data warehouse, and OLAP systems.
Dejan has worked as a database architect, database and application developer, database
administrator, team leader, project manager, writer, and technical trainer.
He is the author of SQL Server 2000 Stored Procedure Programming (www
.trigonblue.com/stored_procedure.htm), coauthor of Windows 2000 Performance
Tuning and Optimization, and three other books, as well as numerous technical
articles for several computer and professional publications.
His career started in Belgrade, Yugoslavia where he graduated on Faculty of
Electrical Engineering. In 1995 he moved to Toronto, Canada and he is currently
in Pittsburgh, U.S.A. He holds certifications for Microsoft Certified Solution
Developer (MCSD), Microsoft Certified Database Administrator (MCDBA), and
Certified SQL Server Programmer Master Level. Dejan is a member of Toronto
SQL Server User Group (www.tssug.com), Visual Basic Developer’s Online
Group (www.visualbyte.com/vbdogs), Pittsburgh SQL Server User Group
(www.pssug.com), and Professional Association for SQL Server (www.sqlpass.org).
Dejan can be contacted by email (dejan’s username on hotmail.com server; to
avoid spam filter, put sp_book in the subject) or the book’s web site (www
.trigonblue.com/sqlxml).
Contents at a Glance
Chapter 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Chapter 2 The SQL Server Environment . . . . . . . . . . . . . . . . . . . . . . . . . 19
Chapter 3 Stored Procedure Design Concepts . . . . . . . . . . . . . . . . . . . . . . 53
Chapter 4 Basic Transact-SQL Programming Constructs . . . . . . . . . . . . . . . . 85
Chapter 5 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Chapter 6 Composite Transact-SQL Constructs: Batches,
Scripts, and Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Chapter 7 Debugging and Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . 207
Chapter 8 Special Types of Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . 259
Chapter 9 Advanced Stored Procedure Programming . . . . . . . . . . . . . . . . . . 341
Chapter 10 Interaction with the SQL Server Environment . . . . . . . . . . . . . . . . 389
Chapter 11 Source Code Management and Database Deployment . . . . . . . . . . . 437
Chapter 12 Stored Procedures for Web Search Engines . . . . . . . . . . . . . . . . . 467
Chapter 13 Introduction to XML for Database Developers . . . . . . . . . . . . . . . 489
Chapter 14 Publishing Information Using SQLXML . . . . . . . . . . . . . . . . . . . . 527
Chapter 15 Modifying Databases Using SQLXML . . . . . . . . . . . . . . . . . . . . . 605
Appendix T-SQL and XML Data Types in SQL Server 2000 . . . . . . . . . . . . . . 659

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669

v
This page intentionally left blank
Contents
Chapter 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Who Should Read This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
What You Will Find in This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Stored Procedure Programming Requirements . . . . . . . . . . . . . . . . . . . 5
XML Programming Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Sample Database and Other Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Sample Database Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Purpose and Design of the Sample Database . . . . . . . . . . . . . . . . . . . . 9
Database Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Chapter 2 The SQL Server Environment . . . . . . . . . . . . . . . . . . . . . . . . . 19


SQL Server 2000 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Service Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Query Analyzer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Enterprise Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
DTS and Import/Export Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
osql and isql . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
SQL Server Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Client Network Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Server Network Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
The Help Subsystem and SQL Server Books Online . . . . . . . . . . . . . . . . . 29
SQL Server on the Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Basic Operations with Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . 31
What Are Stored Procedures? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Execution of Stored Procedures from Query Analyzer . . . . . . . . . . . . . . . . 32
Managing Stored Procedures from Enterprise Manager . . . . . . . . . . . . . . . 36

vii
viii SQL Server 2000 Stored Procedure & XML Programming

Editing Stored Procedures in Enterprise Manager . . . . . . . . . . . . . . . . . . 41


Editing Stored Procedures in Query Analyzer . . . . . . . . . . . . . . . . . . . . 41
Syntax Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Naming Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Why Bother? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Naming Objects and Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Suggested Convention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

Chapter 3 Stored Procedure Design Concepts . . . . . . . . . . . . . . . . . . . . . . 53


Anatomy of a Stored Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Types of Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
The Compilation and Execution Process . . . . . . . . . . . . . . . . . . . . . . . 67
Reuse of Execution Plans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Recompiling Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Storing Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Managing Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Listing Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Viewing Code of Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . 77
Renaming Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Deleting Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Listing Dependent and Depending Objects . . . . . . . . . . . . . . . . . . . . . . 80
The Role of Stored Procedures in the Development of Database Applications . . . . . . . . . 82
Enforcement of Data Integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Consistent Implementation of Complex Business Rules and Constraints . . . . . . . . 83
Modular Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Maintainability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Reduced Network Traffic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Faster Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Enforcement of Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

Chapter 4 Basic Transact-SQL Programming Constructs . . . . . . . . . . . . . . . . 85


T-SQL Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Database Object Qualifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Contents ix

Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Character Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Unicode Character Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Date and Time Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Integer Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Approximate Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Exact Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Monetary Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Binary Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Special Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Local Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Table Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Flow-Control Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Statement Blocks: Begin…End . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Conditional Execution: The If Statement . . . . . . . . . . . . . . . . . . . . . . . 112
Looping: The While Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Unconditional Execution: The GoTo Statement . . . . . . . . . . . . . . . . . . . . 119
Scheduled Execution: The WaitFor Statement . . . . . . . . . . . . . . . . . . . . 121
Cursors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Transact-SQL Cursors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Cursor-Related Statements and Functions . . . . . . . . . . . . . . . . . . . . . . 126
Problems with Cursors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
The Justified Uses of Cursors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

Chapter 5 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131


Using Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
In Selection and Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
As Part of the Selection Criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
In Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
As Check and Default Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Instead of Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Types of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Scalar Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Aggregate Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Rowset Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
x SQL Server 2000 Stored Procedure & XML Programming

Chapter 6 Composite Transact-SQL Constructs: Batches,


Scripts, and Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Batches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Using Batches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Batches and Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
DDL Batches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Self-Sufficient Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Database Scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Autocommit Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Explicit Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Implicit Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Transaction Processing Architecture . . . . . . . . . . . . . . . . . . . . . . . . . 186
Nested Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Named Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
Savepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Locking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
Distributed Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Typical Locking Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203

Chapter 7 Debugging and Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . 207


Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
What Is a “Bug”? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
The Debugging Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Debugging Tools and Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . 212
SQL Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Typical Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Raiserror . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Using Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Why Bother? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Tactics of Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
A Coherent Error Handling Methodology . . . . . . . . . . . . . . . . . . . . . . 243
Xact_Abort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Another Coherent Error Handling Methodology . . . . . . . . . . . . . . . . . . . 252
Contents xi

Chapter 8 Special Types of Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . 259


Types of Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
User-Defined Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
System Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
Extended Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Temporary Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
Global Temporary Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . 270
Remote Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
User-Defined Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Design of User-Defined Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Table-Valued User-Defined Functions . . . . . . . . . . . . . . . . . . . . . . . . 276
Inline Table-Valued User-Defined Functions . . . . . . . . . . . . . . . . . . . . . 279
Managing User-Defined Functions in Enterprise Manager . . . . . . . . . . . . . . 281
Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
Physical Design of After Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . 284
Handling Changes on Multiple Records . . . . . . . . . . . . . . . . . . . . . . . 291
Nested and Recursive Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Trigger Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Instead-of Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
Triggers on Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Trigger Order of Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Managing Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Trigger Design Recommendations . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Transaction Management in Triggers . . . . . . . . . . . . . . . . . . . . . . . . 304
Using Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
Design of Standard SQL Views . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
Dynamic Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
INFORMATION_SCHEMA Views . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Indexed Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Partitioned Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
Using SQL Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336

Chapter 9 Advanced Stored Procedure Programming . . . . . . . . . . . . . . . . . . 341


Dynamically Constructed Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
Executing a String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
xii SQL Server 2000 Stored Procedure & XML Programming

Query By Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344


Data Script Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
Using the sp_executesql Stored Procedure . . . . . . . . . . . . . . . . . . . . . 351
Security Implications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
Optimistic Locking Using timestamp Values . . . . . . . . . . . . . . . . . . . . . . . . . 356
timestamp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
TSEqual() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
timestamp Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
Full-Text Search and Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
Nested Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Using Temporary Tables to Pass a Recordset to a Nested Stored Procedure . . . . . . 365
Using a Cursor to Pass a Recordset to a Nested Stored Procedure . . . . . . . . . . 368
How to Process the Result Set of a Stored Procedure . . . . . . . . . . . . . . . . . 371
Using Identity Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
A Standard Problem and Solution . . . . . . . . . . . . . . . . . . . . . . . . . . 378
Identity Values and Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
Last Identity Value in the Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
GUIDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
A While Loop with Min() or Max() Functions . . . . . . . . . . . . . . . . . . . . . . . . 383
Looping with sp_MSForEachTable and sp_MSForEachDb . . . . . . . . . . . . . . . . . . . 385
Property Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386

Chapter 10 Interaction with the SQL Server Environment . . . . . . . . . . . . . . . . 389


Execution of OLE Automation/COM Objects . . . . . . . . . . . . . . . . . . . . . . . . . 390
Data Type Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
Running Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
Running Windows Script Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
Running/Looping Through DTS Packages . . . . . . . . . . . . . . . . . . . . . . . . . . 395
Interacting with the NT Registry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
xp_regread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
xp_regwrite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
Administration of Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
An Alternative to Job Scheduler . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Stored Procedures for Maintaining Jobs . . . . . . . . . . . . . . . . . . . . . . . 405
Operators and Alerts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
Contents xiii

SQL Server and the Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407


Web Assistant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
Web Task Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
Web Page Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
E-Mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Extended Stored Procedures for Working with E-Mail . . . . . . . . . . . . . . . . 416
Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
Security Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
Implementing Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422
Synchronization of Login and Usernames . . . . . . . . . . . . . . . . . . . . . . 430
Managing Application Security Using Stored Procedures,
User-Defined Functions, and Views . . . . . . . . . . . . . . . . . . . . . . . 432
Managing Application Security Using a Proxy User . . . . . . . . . . . . . . . . . 434
Managing Application Security Using Application Roles . . . . . . . . . . . . . . . 436

Chapter 11 Source Code Management and Database Deployment . . . . . . . . . . . 437


The Concept of Source Code Management . . . . . . . . . . . . . . . . . . . . . . . . . . 438
Introduction to Microsoft Visual SourceSafe . . . . . . . . . . . . . . . . . . . . . 439
Administering the Visual SourceSafe Database . . . . . . . . . . . . . . . . . . . 440
Adding Database Objects to Visual SourceSafe in Visual Studio .NET . . . . . . . . . 440
Managing Create Scripts in Visual Studio .NET . . . . . . . . . . . . . . . . . . . . 443
Visual SourceSafe Explorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
Adding Database Objects to Visual SourceSafe: Traditional Approach . . . . . . . . . 451
Database Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
Deployment of a Complete Database: Traditional Approach . . . . . . . . . . . . . 453
Deployment of Individual Objects . . . . . . . . . . . . . . . . . . . . . . . . . . 455

Chapter 12 Stored Procedures for Web Search Engines . . . . . . . . . . . . . . . . . 467


Characteristics of the Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
A Simple Solution... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
...and Its Disadvantages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
Available Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
Result Splitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
Quick Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
Advanced Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486
xiv SQL Server 2000 Stored Procedure & XML Programming

Chapter 13 Introduction to XML for Database Developers . . . . . . . . . . . . . . . 489


XML (R)evolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
Introduction to XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
Introduction to Markup Languages . . . . . . . . . . . . . . . . . . . . . . . . . 492
Building Blocks of Markup Languages . . . . . . . . . . . . . . . . . . . . . . . . 492
XML Elements and Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
Processing Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494
Document Type Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
XML Comments and CDATA sections . . . . . . . . . . . . . . . . . . . . . . . . . 496
Character and Entity References . . . . . . . . . . . . . . . . . . . . . . . . . . 497
XML Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498
Structure of XML Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
XML Parsers and DOM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
XML Document Quality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
XML Schema and XML Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
XML–Data Reduced (XDR) Schema . . . . . . . . . . . . . . . . . . . . . . . . . 502
XML Schema (XSD) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
Linking and Querying in XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
XPointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519
XPath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520
Transforming XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522
XSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
XSLT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524
Why XML? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524
Exchange of Information Between Organizations . . . . . . . . . . . . . . . . . . 524
Information Publishing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526

Chapter 14 Publishing Information Using SQLXML . . . . . . . . . . . . . . . . . . . . 527


For XML Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528
Auto Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
Aggregate Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534
Computed Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534
The Elements Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534
The XMLData Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535
The BINARY Base64 Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536
Raw Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537
Explicit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538
Contents xv

Publishing Database Information Using HTTP . . . . . . . . . . . . . . . . . . . . . . . . 547


Configuring Database Access Through HTTP . . . . . . . . . . . . . . . . . . . . . 548
Accessing Database Information Using a URL . . . . . . . . . . . . . . . . . . . . 552
Troubleshooting Virtual Directories . . . . . . . . . . . . . . . . . . . . . . . . . 554
Executing a Stored Procedure Through HTTP . . . . . . . . . . . . . . . . . . . . 556
Accessing Database Information Using Templates . . . . . . . . . . . . . . . . . . 557
POSTing Queries to the Server . . . . . . . . . . . . . . . . . . . . . . . . . . . 567
XML Views Based on Annotated XDR Schemas . . . . . . . . . . . . . . . . . . . . 571
XML Views Based on Annotated XSD Schemas . . . . . . . . . . . . . . . . . . . . 582
Programmatic Database Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588
Retrieving XML Data Using SQLXML Managed Classes . . . . . . . . . . . . . . . . 588
Retrieving XML Data Using ADO.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
Using SqlCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
Using DataSet Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598
Client-Side XML Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
Using URL Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
Using Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
Using SQLXML Managed Classes . . . . . . . . . . . . . . . . . . . . . . . . . . 601
Processing of Queries with the For XML Clause . . . . . . . . . . . . . . . . . . . 602

Chapter 15 Modifying Databases Using SQLXML . . . . . . . . . . . . . . . . . . . . . 605


OpenXML() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606
Document Preparation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606
Closing the Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607
Retrieving the XML Information . . . . . . . . . . . . . . . . . . . . . . . . . . . 608
Metaproperties in OpenXML() . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611
What if an XML Document Is Longer Than 8000 Characters? . . . . . . . . . . . . . 613
UpdateGrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615
Executing UpdateGrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
Element-centric vs. Attribute-centric UpdateGram . . . . . . . . . . . . . . . . . . 619
UpdateGrams with Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . 619
Setting Parameters to Null . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
Returning Identifier Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622
Special Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624
UpdateGrams Behind the Scene . . . . . . . . . . . . . . . . . . . . . . . . . . . 624
Optimistic Locking with UpdateGrams . . . . . . . . . . . . . . . . . . . . . . . . 625
Multiple Records and Multiple Tables in a Single UpdateGram . . . . . . . . . . . . 627
xvi SQL Server 2000 Stored Procedure & XML Programming

DiffGrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
Using DiffGrams to Insert Data . . . . . . . . . . . . . . . . . . . . . . . . . . . 629
Using DiffGrams to Update Data . . . . . . . . . . . . . . . . . . . . . . . . . . 631
Using DiffGrams to Delete Data . . . . . . . . . . . . . . . . . . . . . . . . . . . 633
Processing Multiple Records Using DiffGrams . . . . . . . . . . . . . . . . . . . . 634
DiffGrams Behind the Scene . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
Executing DiffGrams Programmatically Using SqlXmlCommand . . . . . . . . . . . 636
Executing DiffGrams Using URLs . . . . . . . . . . . . . . . . . . . . . . . . . . 636
Generating DiffGrams After DataSet Change . . . . . . . . . . . . . . . . . . . . 637
Debugging DiffGrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638
SQLXML BulkLoad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639
Executing SQLXML BulkLoad from a .NET Application . . . . . . . . . . . . . . . . 639
Error Log File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640
Executing BulkLoad from DTS (Using VBScript) . . . . . . . . . . . . . . . . . . . 641
Schema Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 642
BulkLoad Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643
Data Integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643
Table Lock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 644
Using SQLXML BulkLoad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 644
Mapping Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 644
XML Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647
SOAP Messages and XML Web Services Architecture . . . . . . . . . . . . . . . . . 647
Using SQLXML to Create XML Web Services . . . . . . . . . . . . . . . . . . . . . 648
Creating .NET SOAP Clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 650

Appendix T-SQL and XML Data Types in SQL Server 2000 . . . . . . . . . . . . . . 659

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669
CHAPTER

Introduction
1
IN THIS CHAPTER:
Who Should Read This Book
What You Will Find in This Book
Requirements
Sample Database and Other Resources

1
2 SQL Server 2000 Stored Procedure & XML Programming

W elcome to SQL Server 2000 Stored Procedure & XML Programming.


This book identifies and describes the key concepts, tips and techniques,
and best practices the professional developer needs to master in order to
take full advantage of stored procedures in the SQL Server development environment.
Microsoft SQL Server is the relational database management system (RDBMS)
of choice for a growing number of business organizations and professional database
and application developers. The reasons for this growing popularity are quite simple:

 Integration No other RDBMS integrates as fully and cleanly with applications


and integrated development environments (IDEs) designed to run on the ubiquitous
Microsoft Windows platform.
 Ease of use SQL Server provides Enterprise Manager and Query Analyzer to
allow DBAs to design, develop, deploy, and manage database solutions. These
interfaces automate repetitive tasks and provide simple ways to perform complex
operations. SQL Server integrates seamlessly with development tools such as
Visual Basic and Visual Interdev to allow developers to design and develop
client/server or Internet solutions rapidly.
 Flexibility You can use different features within SQL Server to achieve
similar results. (Of course, with flexibility comes choice, and choice means
that the developer is responsible for choosing the most appropriate means of
achieving an end. This book will help you make those choices.)
 Power SQL Server makes large amounts of data available to large numbers
of concurrent users while maintaining the security and integrity of the data. At
the time of this writing, SQL Server holds the record in TPC-C benchmark
tests for performance and price/performance (see www.tpc.org).

When I began working with SQL Server, reference materials relating to the
development and deployment of stored procedures were rare and not particularly
helpful. These materials described basic concepts, but the examples presented were
often trivial and not complex enough to be applied to real-world situations in which
aspects such as error handling, debugging, naming conventions, and interfaces to other
applications are critical. As the legions of application developers and development
DBAs migrate from Microsoft Access to SQL Server, and as SQL Server becomes
the leading database for mission-critical application development, the need for more
advanced work on SQL Server stored procedures becomes even more critical.
Chapter 1: Introduction 3

Who Should Read This Book


This book has been written to fill this gap, and thus it has been written with a wide
audience in mind. Ideally, it will be neither the first nor the last book you read on SQL
Server, but it may be the one you refer to and recommend the most. Above all, this book
has been written to help professional developers get the most out of SQL Server stored
procedures and SQLXML extensions and to produce quality work for their clients.
If you are an experienced SQL Server developer, you will find this book to be an
essential reference text full of tips and techniques to help you address the development
issues you encounter in the course of your day-to-day development activities.
If you have some experience with SQL Server development, but substantially more in
other programming environments such as Visual Basic, you will find this book useful as
a tool to orient yourself with the SQL Server environment and become proficient more
quickly with SQL Server stored procedure and SQLXML concepts and methods. You
will be able to incorporate effective, swift stored procedures into Visual Basic code and
SQLXML methods and queries into your client Windows or web applications.
If you are a novice SQL Server developer, the concepts, tips, and techniques you
will learn in reading this book and working through the exercises will help you attain
the knowledge, skills, and good habits that will help you become an accomplished
professional.
I hope that this book remains close to your workstation for a long time. Indeed, in the
course of this book’s useful life, you may in turn be all three of the users just described.

What You Will Find in This Book


Each chapter in this book (aside from the one you are reading, which is introductory
in nature) will provide conceptual grounding in a specific area of the SQL Server
development landscape. The first 12 chapters are dedicated to stored procedure
programming, and Chapters 13, 14, and 15 are focused on XML programming on
SQL Server 2000.
As you may have gathered, this chapter describes the content of this book, as well
as its intended audience, and describes a sample database that we will use throughout
the book to demonstrate stored procedure development.
Chapter 2, “The SQL Server Environment,” provides a 30,000-foot overview of
the Transact-SQL language, SQL Server tools, and stored procedure design.
Chapter 3, “Stored Procedure Design Concepts,” explores SQL Server stored
procedure design in greater detail, with particular attention paid to the different
types of stored procedures, their uses, and their functionality.
4 SQL Server 2000 Stored Procedure & XML Programming

Chapter 4, “Basic Transact-SQL Programming Constructs,” describes Transact- SQL,


the ANSI SQL-92–compliant programming language used to write scripts in SQL
Server. This chapter summarizes data types, variables, flow control statements, and
cursors in the context of SQL Server 2000.
Chapter 5, “Functions,” describes the extensive set of built-in functions available
in SQL Server 2000 and how to use them in various common situations.
Chapter 6, “Composite Transact-SQL Constructs: Batches, Scripts, and Transactions,”
describes the various ways in which you can group Transact-SQL statements for
execution.
Chapter 7, “Debugging and Error Handling,” provides a coherent approach to the
identification and resolution of defects in code and a coherent strategy for handling
errors as they occur.
Chapter 8, “Special Types of Procedures,” describes user-defined, system, extended,
temporary, global temporary, and remote stored procedures as well as other types of
procedures in Transact-SQL, such as user-defined functions, table-valued user-defined
functions, After triggers, Instead-of triggers, standard SQL views, indexed views,
INFORMATION_SCHEMA views, and local and distributed partitioned views.
Chapter 9, “Advanced Stored Procedure Programming,” introduces some advanced
techniques for coding stored procedures, such as dynamically constructed queries,
optimistic locking using timestamps, and nested stored procedures.
Chapter 10, “Interaction with the SQL Server Environment,” focuses on the ways
in which you can use system and extended stored procedures to interact with the SQL
Server environment, and discusses the ways in which user-defined stored procedures
can help you leverage the existing functionality of various elements within the SQL
Server environment.
Chapter 11, “Source Code Management and Database Deployment,” demonstrates
how you can manage and deploy Transact-SQL source code from development to
the test and production environment. It explains and demonstrates two alternative
approaches—one using Visual Studio .NET and the other, more traditional, using
scripts developed in Transact-SQL and VBScript.
Chapter 12, “Stored Procedures for Web Search Engines,” presents an example of
how to use stored procedures in a web application that queries the database system.
Several optimization techniques are used to avoid typical design problems and improve
the performance.
Chapter 13, “Introduction to XML for Database Developers,” introduces XML as
the markup language for information exchange and publishing, and then focuses on
complementary features and technologies like DTDs, XML Schemas, and XPath as
they are used in SQL Server 2000.
Chapter 14, “Publishing Information Using SQLXML,” describes methods for
returning an XML stream instead of a recordset from SQL Server 2000.
Chapter 1: Introduction 5

Chapter 15, “Modifying Databases Using SQLXML,” describes several methods


for parsing XML and updating database tables.
The appendix, “T-SQL and XML Data Types in SQL Server 2000,” provides you
with tables that list data types in use in SQL Server 2000 and the way they map.

Requirements
To make full use of this book, you will need access to a server running one of the
following versions of SQL Server 2000 or SQL Server 2000 (64-bit):

 Enterprise Edition Supports all features and scales to enterprise level;


supports up to 32 CPUs and 64GB RAM
 Standard Edition Scales to the level of departmental or workgroup servers;
supports up to four CPUs and 2GB RAM
 Evaluation Edition Supports all features of Enterprise Edition; use is limited
to 120 days; available for download over the Web

Stored Procedure Programming Requirements


You can also perform most of the stored procedure programming–oriented activities
described in this book using a stand-alone PC with Windows 98, Windows 2000, or
Windows NT Workstation to run one of the following versions of Microsoft SQL
Server 2000:

 Personal Edition Designed for mobile or stand-alone users and applications;


does not support some advanced features, such as fail-over clustering, publishing
of transactional replications, OLAP Server, or Full Text Search; supports up to
two CPUs
 Developer Edition Licensed to be used only as a development and test
server, although it supports all features of Enterprise Edition
 Desktop Engine Distributable but stripped-down version that software
vendors can package and deploy with their systems; part of Microsoft Access
and Visual Studio; also known as MSDE; does not contain administrative tools
such as Enterprise Manager, Query Analyzer, and Books Online; does not
support advanced features such as Analysis Services and replication; database
size is limited to 2GB
6 SQL Server 2000 Stored Procedure & XML Programming

Although MSDE is compatible with all other versions of SQL Server 2000 and
thus makes an excellent development tool in a stand-alone environment, the absence
of administrative tools such as Enterprise Manager and Query Analyzer means that
some of the information you find in this book will not be usable right away. I recommend
that you obtain some other version (such as Developer Edition or Evaluation Edition),
or at least buy a Server/Per-Seat Client Access License (CAL) that will allow you to
use administrative tools against MSDE.

XML Programming Requirements


To explore and use XML programming features, you need to install and use:

 XML for SQL Server Web release (SQLXML) I recommend that you
download and install at least SQLXML 3.0, Service Pack 1.
 Microsoft SOAP Toolkit Download version 2, Service Pack 2 or newer.
 Microsoft XML Core Services (MSXML) Use version 4, Service Pack 1 or
newer. Earlier versions were called Microsoft XML Parser.
 Internet Information Services (IIS) Use version 5 or newer.
 Internet Explorer Use version 5 or newer.

Sample Database and Other Resources


You may have noticed that this book does not include a CD. SQL Server development
is a dynamic field, as you will see if you compare the first and second editions of this
book. Rather than increase the cost of the book by adding a CD, which would be out
of date almost before it hits the bookstore, the publisher and I have chosen to make
additional resources available for download via the Web. In addition to the sample
database (more information on that in just a bit) that I have created and will use
through most of this book, other resources available include:

 Several tools for source code management and database deployment Set
of T-SQL, VBScript and .NET tools for generating, managing, and deploying
code of database objects.
 Sample SQLXML code Visual Studio .NET sample projects for demonstrating
use of SQLXML managed classes.
Chapter 1: Introduction 7

 Periodic updates As noted earlier, SQL Server development is a dynamic


field, and thus a book on SQL Server needs to be dynamic to meet the evolving
needs of its audience. Reader feedback is important to me. Check my web site
(www.trigonblue.com) for periodic updates on issues raised by readers.
 Author’s web site Aside from being the source of the sample database
and periodic update downloads, the Trigon Blue web site provides a wealth of
excellent reference materials and links. Visit the site often for SQL Server and
e-business news. While you’re there, have a look at the many articles and white
papers, and check out Trigon Blue’s many product and service offerings.

The subject of the Asset sample database created for this book is an asset
management system within a fictional organization. Although the database is
based on real-world experience within financial institutions, it is also applicable
in many other environments.
The main purpose of the database is to track assets. Assets are defined as equipment,
and all variations in their content, attributes, and shape are recorded as values of
properties. The Inventory table tracks location, status, leasing information, and who
is currently using each asset. To transfer an asset from one location to another, to
assign assets to a different owner or department, to request maintenance, or to request
upgrades or new assets, users of the database use orders and order items. Activities
performed to complete the order are recorded in the charge log and interdepartment
invoices are generated. There are lookup tables used to track provinces, lease
frequencies, statuses, and other details.

Sample Database Installation


You should download this database and install it on your server before you begin to
read the rest of this book. To download and install the sample Asset database:

1. Visit www.trigonblue.com/sqlxml
2. Click the Download Sample DB link.
3. Click the Asset sample database link to start the download. When prompted,
opt to save the file to disk. Remember the location to which you saved the file.
4. Unzip the contents of the Zip file into the Data folder of the machine on
which SQL Server is installed (usually \Program Files\Microsoft SQL
Server\MSSQL\Data).
8 SQL Server 2000 Stored Procedure & XML Programming

5. Make sure that SQL Server is running. If necessary, run SQL Server Service
Manager from Programs | MS SQL Server or use the system tray icon. If
necessary, start the SQL Server service.

6. Run Query Analyzer (select Programs | MS SQL Server | Query Analyzer).


7. You will be prompted to connect to SQL Server. Type the server name and log
in as system administrator (sa). If the password has not been set, leave the
password blank (an empty string).

Query Analyzer opens a query window pointing to the master database.


Random documents with unrelated
content Scribd suggests to you:
HORNBEAM
(Ostrya Virginiana)

his tree belongs to the birch family and is closely related to

T the alders and to blue beech. Four species of hornbeam are


known in the world, and two of them are in the United States.
One is well known to most persons who are familiar with
eastern hardwood forests, but the other is seldom seen
because of the limited extent of its range.
The well-known hornbeam is found in the valley of the St. Lawrence
river, throughout Nova Scotia and Ottawa, along the northern shore
of Lake Huron to northern Minnesota, south through the northern
states and along the Alleghany mountains to the Chattahoochee
region of western Florida; through eastern Iowa, southeastern
Missouri and Arkansas, eastern Kansas, Oklahoma and the Trinity
river region of Texas. It is known as ironwood, hop-hornbeam,
leverwood, and hardhack.
The Indians were small users of wood except for fuel, but they had
places where they put wood to special uses. They chose hornbeam,
when they could get it, for one of these places. It was a favorite
material for the handles of their stone warclubs. The stone heads
were chipped to various forms, but were usually egg-shaped with a
groove round the middle for fixing the handle. This was made fast
with thongs of rawhide, and was generally nearly or quite two feet
long, and slender as a golf stick. Great strength and a high degree of
elasticity were required to stand the strain when a warrior swung his
club in battle. Hornbeam meets these requirements exactly, and
doubtless the Indian found this out by experience. It is about thirty
per cent stronger than white oak, and forty-six per cent more elastic.
The demand for warclub handles made no great inroads on the
hornbeam supply, but it affords proof that the Indians sometimes
used good judgment.
The different names of this tree describe some characteristic of the
wood or foliage. The fruit resembles hops, hence one of the names.
Hardness gives it the other names by which it is known. It is the
custom nearly everywhere to call any wood ironwood if it is extra
hard. No fewer than eleven species of the United States are known
as ironwood in some parts of their ranges.
The leaves of hornbeam are simple and alternate; they taper to a
sharp point at the end, while the base is rounded. They are doubly
and sharply serrate. In color they are dark green above, and lighter
below, tufted in places, resembling birch leaves in some respects,
although they are quite different in texture, the leaves of birch being
glossy, while those of ironwood are rough. They are joined to the
twig with a short petiole, hardly a fourth of an inch in length.
The flowers grow in long catkins, staminate ones sometimes more
than two inches long, covered with fringed scales. The pistillate
catkins are usually shorter. Hornbeam blooms in April and May and
its fruit ripens in August and September. The seed is a small nut
equipped with balloon-like wings, intended for wind distribution. The
seeds are often carried, rolled, and tumbled considerable distances.
They keep on going until their wings are torn off or wear out, or
until they become inextricably entangled among twigs or other
obstacles. Comparatively few of the seeds ever find lodgment in
situations suitable for germination. Consequently, hornbeam is
scarce.
It is not easy to state the average size of the hornbeam, though it is
usually small and never very large. Sometimes it reaches a height of
fifty or sixty feet and a diameter of two or more, but such sizes are
unusual. Trees a foot in diameter and forty feet high are more
common. The foliage is thin, and the tree is satisfied to grow in
shade, provided the shadows are not too dense. The leaves must
have a little sunshine, and the flecks that fall through the open
spaces in the forest canopy high above, suffice. The hornbeam
makes no effort to overtop its fellow trees; but when it grows in the
open, as on a rocky bank or ridge, where it catches the full light, the
crown puts on more leaves, and multiplies its branches, and it is no
longer the lean tree which some of the Indians called it. Forest
grown specimens produce clear trunks, but those in the open are
limby almost to the ground.
Hornbeam has neither smell nor taste. It burns well, the embers
glowing brightly in still air. The weight of a cubic foot of seasoned
wood is fifty-one pounds. It is strong, hard, heavy, tough, and
exceedingly durable when exposed to variable weather, or when in
contact with the soil. It takes a beautiful polish. Trees more than a
foot in diameter are often found to be hollow.
The wood is strong, hard, tough, durable in contact with the soil;
heartwood light brown, tinged with red, or often nearly white; thick,
pale sapwood which generally does not change to heart for forty or
fifty years. The annual rings are not uniform in appearance. Some
are easily distinguishable, while others are vague. This variation is
due to the irregular development of the dark summerwood in the
outer portion of the rings. It is at times distinct and again is hardly
discernible.
The wood is diffuse-porous, and the pores are too small to be easily
seen by the naked eye. The medullary rays are small and obscure.
In quarter-sawed wood they show as a silvery gloss, but the
appearance is too monotonous to be attractive. Neither is there
striking figure when the wood is sawed tangentially, because of the
small contrast in the different parts of the yearly ring. Hornbeam
may, therefore, be listed among woods which have little or no figure.
No one ever thinks of using it for the sake of its beauty. Because of
the small size and limited quantity hornbeam will never come into
commercial prominence. Its uses are almost entirely local and
domestic. The lumberman or the farmer selects a hornbeam sapling
as being the best material obtainable for making a wagon or sleigh
tongue, a skid, or a lever. The farmer often laboriously works a
section of the flint-like wood into minor agricultural implements.
The statistics of sawmill cut in the United States do not mention
hornbeam even among such minor species as holly, Osage orange,
alder, and apple. However, it is known that an occasional log goes to
sawmills in the Lake States, and doubtless in other regions, and in
some instances the wood is kept separate from others and is sold to
fill special orders. Manufacturers of farm tools consider it the best
wood for rake teeth. That use has come down from the time when
farmers made their own rakes and pitchforks. They learned the
wood’s value by experience, and manufacturers cater to the trade.
It is sometimes called lever wood, and that name dates from long
ago when the man who needed a lever went into the woods and cut
one to suit his needs. The modern lever is usually somewhat
different and partakes more of the nature of a handle. They are seen
in sawmills where they manipulate the carriage machinery; on
certain agricultural implements where their function is to throw
clutches in and out of gear; sometimes they are used as the handle
by which the rudder of a small boat is controlled; and occasionally
the lever has a place as an adjunct of a wagon or log-car brake. In
all of these uses strength and stiffness are required, and durability is
duly considered.
Wagon makers and repairers find several uses for hornbeam. It
would be more frequently employed if it were more plentiful. Nearly
any blacksmith who runs a repair shop for vehicles will testify to
that. It fulfills every requisite for axles; is made into felloes for heavy
wagons; and is considered the best obtainable wood for the tongues
of heavy logging wheels and stone wagons.
Among various occasional uses of this wood it is listed by the
manufacturers of reels for garden hose; rungs for long ladders;
stakes for sleds, and also for cross pieces and parts of runners of
sleds; wedges for the makers of machinery; and hammer and
hatchet handles. It is a pretty active competitor of dogwood for
some of these uses, and it has been suggested for shuttles, but no
report of its use in that capacity seems to have been made.
One of its most common uses is as fence posts. Few lines of fence
are built exclusively of hornbeam posts, because not enough can be
had in one place; but posts are cut singly or a few together from
Maine to Arkansas, and the aggregate number is large. The wood is
said to outlast the heartwood of white oak when in contact with the
ground, and it is so strong that posts of small size stand the pull of
wires or the weight of planks or pickets.
Hornbeam is of slow growth and there is little reason to believe that
it will ever be seriously considered by timber growers; but it will
doubtless win its way to favor as an ornamental tree. It has been
planted in city parks in New England and elsewhere, and its form,
foliage, and habits are much liked. The pale green pods or cones—
they are not exactly the one or the other—remain a long time on the
branches and are delicately ornamental until after the autumn frosts
change their green into brown. Then comes the flying time of the
balloon seeds, and that is an interesting period in parks and yards
where the tree’s habits may be closely studied.
Knowlton Hornbeam (Ostrya knowltoni) is interesting chiefly on account of its
extremely limited range, and its far removal from all its kin. It is an exile in a
distant country. It has thus far been found only on the southern slope of the
canyon of the Colorado river in Arizona, about seventy miles north of Flagstaff. It
occurs at an elevation of 6,000 or 7,000 feet above the sea. Trees are twenty or
thirty feet high and twelve or eighteen inches in diameter, and trunks usually
divide a foot or two above the ground into three or more branches, which are
often crooked and contorted. Such sizes and forms could not be of much value for
anything but fuel, even if abundant. The heart is light reddish-brown, sapwood
thin. The leaves are round instead of pointed at the apex, as with the other
hornbeam; but the flowers and fruit are much the same. Botanists speculate in
vain as to how this species happens to be so far removed from other members of
its family.
SILVERBELL

Silverbell
SILVERBELL TREE
(Mohrodendron Carolinum)

his tree belongs to the storax family, which is not a very

T numerous family as forest families are generally counted, but


it is old and highly respectable. Its members are found in the
old world and the new in both North and South America, in
Europe, Asia, and the Malay Archipelago. Trees of the storax
family produce, or they are supposed to produce, resins and gums,
balsams, and aromatic exudations, but some give little or none. The
priests and soothsayers of idolatrous nations of ancient times laid
great stress on storax. They insisted on having the resin as an
adjunct to their superstitious rites. It was the incense offered in their
worship, and they compassed sea and land to obtain it for that
purpose. It is not improbable that the southern peninsulas of Asia
and the far-off Molucca islands were visited in ancient times to
procure the incense which ultimately found its way to the
Mediterranean regions.
It is, therefore, interesting to find that two members of the old
storax family are quietly living in the coast region and among the
mountains of the southeastern part of the United States. No one has
ever suspected that they might be capable of yielding resinous
incense suitable for the altars of heathen gods. They are the
silverbell tree, and its little cousin, the snowdrop tree
(Mohrodendron dipterum). They have had common names a long
time, but their botanical names are the result of a recent christening.
They are named from Charles Mohr who wrote an interesting book
on the flora of Alabama. The silverbell tree is the larger of the two
and deserves first consideration.
It has a somewhat extensive range, but in some parts it is so scarce
that few persons ever see it. It is found from the mountains of West
Virginia to southern Illinois, south to middle Florida, northern
Alabama, and Mississippi, and through Arkansas and western
Louisiana to eastern Texas. Under cultivation, this tree is known as
the snowdrop tree in Rhode Island, Pennsylvania, North Carolina,
South Carolina, Florida, and Louisiana. In Rhode Island, under
cultivation, it is also sometimes known as the silverbell tree, and
bears the same name in Alabama, Florida, and Mississippi. In parts
of Tennessee it is known as the wild olive tree, and in other parts of
the state as the bell tree. In various localities in Alabama it is
referred to as the four-winged halesia; and in others as
opossumwood. It is indiscriminately known in various sections of
Texas as the rattlebox and calicowood, and some of the furniture
manufacturers in North Carolina list it as box elder, though it is only
distantly related to the true box elder. In the Great Smoky mountains
in Tennessee, where the species reaches its greatest development, it
bears a variety of names, among them being tisswood, peawood,
bellwood, and chittamwood.
The tree varies in size from a shrubby form so small that it is
scarcely entitled to the name of tree, up to a height of eighty, ninety,
and even more than 100 feet with diameters up to nearly four feet.
The largest sizes occur only among the ranges of the Great Smoky
mountains in Blount, Sevier, and Monroe counties, Tennessee. No
reason is known why this tree in that region should so greatly
exceed its largest dimensions in other areas; but most species have
a locality where the greatest development is reached, and this has
found the favorable conditions in the mountains of eastern
Tennessee. Some of the trees measure sixty feet or more to the first
limbs.
Lumbermen of the country are not generally acquainted with
silverbell, as is natural since its commercial range is so limited. It is
not listed in statistics of sawmill cut or of veneer mills. The wood-
using industries of the country do not report it, except in the one
state, North Carolina, and there in very small amounts. Doubtless, it
is occasionally used elsewhere, but it escapes mention in most
instances. It has been made into mantels at Knoxville, Tennessee,
and passes as birch.
The wood is light, soft, usually narrow-ringed, color light brown, the
thick sapwood lighter. It weighs thirty-five pounds per cubic foot,
and when burned it yields a low percentage of ash. The wood’s chief
value is due to its color and figure. Best results are not obtained by
sawing the logs into lumber, because the handsomest part of the
figure is apt to be lost. It is preëminently suited to the cutting of
rotary veneer. By that method of conversion the birdseye and the
pitted and mottled effects are brought out in the best possible
manner. Veneers so cut from logs selected for the figure, possess a
rare beauty which no other American wood equals. There is a
pleasing blend of tones, which are due to the direction in which the
distorted grain is cut. This distinguishes the wood from all others
and gives it an individuality. Much of the figure appears to be due to
the presence of adventitious buds, similar to those supposed to be
responsible for the birdseye effect in maple.
The leaves of silverbell are bright green at maturity and are from
four to six inches long and two or three wide. They turn yellow
before falling in autumn. The flowers give the tree its name, for they
resemble delicate bells, about one inch in length. They appear in
early spring when the leaves are one-third grown, on slender,
drooping stems from one to two inches long. The trees are loaded
throughout the whole crown, and present an appearance that is
seldom surpassed for beauty in the forests of this country.
The fruit is peculiar and is not particularly graceful. It has too much
the appearance of the load carried by a well-fruited vine of hops. It
ripens late in autumn and persists during most of the winter. There
is nothing in its color, shape, or taste to tempt birds or other
creatures to make food of it, though, under stress of circumstances,
they may sometimes do so. The fruit is two inches or less in length
and an inch wide, and has four wings, which seem to be practically
useless for flight. The seed is about half an inch long.
The bark of the trunk is bright red-brown and about half an inch
thick, with broad ridges which separate on the surface into thin
papery scales. The young branches wear an early coat of thick, pale
wool or hairs, light, reddish-brown during the first summer, but later
changing to an orange color.
The botanical range of the species is extensive, though the tree-form
is confined to a few counties among the southern Appalachian
mountains. The northern limit of its range is in West Virginia where it
is so scarce that many a woodsman never recognizes it. Unless it is
caught while in the full glory of its bloom, it attracts no attention. It
is not there a tree, but a shrub, hidden away among other growth,
along mountain streams or on slopes where the soil is fertile. The
blooming shrub might, at a distance, be mistaken for a dogwood in
full blossom, but a closer inspection corrects the mistake.
It is true of this species as of many others that the range has been
greatly extended by planting. The bell-like white flowers early drew
attention of nurserymen who were on the lookout for trees for
ornamental planting. It was carried to Europe long ago, and graces
many a yard and park in the central and northern countries of that
continent. It now grows and thrives in the United States six hundred
miles northeast of its natural range, where it endures the winters of
eastern Massachusetts, blooms as bounteously as in its native
haunts among the shaded streams of the Alleghany mountains.
Snowdrop Tree (Mohrodendron dipterum) is a near relative of the
silverbell tree, and looks much like it, except that it is smaller, has
larger leaves, and the flowers are creamy-white. The two occupy the
same territory in part of their ranges, but they differ in one respect.
The silverbell tree grows with great luxuriance among the mountains
while the snowdrop tree keeps to the low country and is seldom or
never found growing naturally at any considerable elevation. It
prefers swamps or damp situations near the coast. While the
silverbell tree’s range includes West Virginia, that of the snowdrop
extends no farther north than South Carolina. It follows the coast to
Texas, and runs north through Louisiana to central Arkansas. Its
range has been greatly enlarged by planting, and the northern
winters do not kill it on the southern shores of Lake Erie. The largest
trees are about thirty feet high and six inches in diameter, but the
growth in most places is shrubby. Leaves are four or five inches long
and three or four wide. Flowers are one inch long and are borne in
profusion. They constitute the tree’s chief value as an ornament,
though the foliage is attractive. The bloom lasts a month or six
weeks, from the middle of March till the last of April. The fruit has
two wings instead of four, as with silverbell, but occasionally two
rudimentary wings are present. The wood is light, soft, strong, color
light brown, with thicker, lighter sapwood. The smallness of the
trunks makes their use for lumber impossible. The species is
valuable for ornamental purposes only, and has been planted both in
this country and Europe. It has a number of names by which it is
known in different localities, among them being cowlicks in
Louisiana, and silverbell tree in the North where it has been planted
outside of its natural range.
SYCAMORE

Sycamore
SYCAMORE
(Platanus Occidentalis)

robably no person with a practical knowledge of trees ever

P mistakes sycamore for anything else. The tree stands clear-cut


and distinct. Until the trunk becomes old, it sheds its outer
layer of bark yearly, or at least frequently, and the exfoliation
exposes the white, new bark below. The upper part of the
trunk and the large branches are white and conspicuous in the
spring, and are recognizable at a long distance. No other tree in the
American forest is as white. The nearest approach to it is the paper
birch of the North, or the white birch of New England.
Notwithstanding the tree’s individuality, it has a good many names.
It is generally known as sycamore throughout the states of the
Union, but it is frequently called buttonwood in Vermont, New
Hampshire, Rhode Island, Massachusetts, New York, New Jersey,
Pennsylvania, Delaware, South Carolina, Alabama, Mississippi,
Louisiana, Texas, Arkansas, Missouri, Illinois, Nebraska, Michigan,
Minnesota, Ohio, and Ontario; buttonball tree in several of the
eastern states and occasionally in Illinois, Iowa, Ohio, Michigan, and
Nebraska; the plane tree in Rhode Island, Delaware, South Carolina,
Kansas, Nebraska, and Iowa; the water beech in Delaware; the
platane, cottonier, and bois puant in Louisiana. Probably the finest
growth of the sycamore ever encountered was in Ohio and Indiana,
and these states still contain isolated patches of magnificent
specimens of the wood. The Black Swamp of Ohio was originally a
famous sycamore country, of which Defiance was the center of
lumber manufacture. Many parts of Indiana produced a good
sycamore growth, and a considerable amount of timber of excellent
quality still exists, but is now largely owned by farmers who are
generally holding it out of the market.
The range of sycamore extends from Maine to Nebraska, and south
to Texas and Florida. It is one of the largest of American hardwoods,
and in diameter of trunk it is exceeded by none. Trees are on record
that were from ten to fourteen feet in diameter, and it was not
unusual in the primeval forests for them to tower nearly or quite
125. In height a number of hardwoods exceed it, the yellow poplar
in particular; but none of them has a larger trunk than the largest
sycamores. However, the mammoths are generally hollow. The heart
decays as rings of new growth are added to the outside of the shell.
So large were the cavities in some of the sycamores in the original
forests that more than one case is on record of their being used by
early settlers as places of abode.
The tree thrives best in the immediate vicinity of rivers and creeks. It
needs abundance of water for its roots, but is not insistent in its
demand for deep, fertile soil, for it grows on gravel bars along water
courses, provided some soil and sand are mixed with the gravel.
Great age is doubtless attained, but records are necessarily lacking
in cases where the annual rings of growth must be depended upon;
because the hollow trunks have lost most of their rings by decay.
Sycamore bears abundance of light seed which is scattered short
distances by wind and much farther by running water. Its ideal place
for germinating is on muddy shores and wet flats. Here the seeds
are deposited by wind and water, and in a short time multitudes of
seedlings spring up. Though most of them are doomed to perish
before they attain a height of a few feet, survivors are sufficient to
assure thick stands on small areas. The trunks grow tall rapidly, and
until they reach considerable size, they remain solid and make good
sawlogs; but at an age of seventy-five or 100 years, deterioration is
apt to set in; some die, others become hollow, and the result is a
good stand of large sycamores is unusual. The veterans are
generally scattered through forests of other species.
The statement has often been made in recent years that sycamore is
becoming very scarce and that the annual output is rapidly declining.
Statistics do not show a declining output. The cut of sycamore in
1909 was approximately twice as great as in 1899. It is true that the
supply is not very large, and it never was large compared with some
other hardwoods; but it appears to be holding its own as well as
most forest trees. The cut in the United States in 1910 was
45,000,000, and it was credited to twenty-six states. Indiana was
the largest contributor, and it had held that position a long time.
States next below it in the order named were Missouri, Arkansas,
Tennessee, Kentucky, Ohio, and Illinois. Doubtless some of the
sycamore lumber now going to market has grown since old settlers
cut the primeval stands when they cleared their fields. It will
continue to grow, and since it usually occupies waste places, it may
be depended upon to contribute pretty regularly year by year during
time to come. It is one of the forest trees which have never suffered
much from fires, because it grows in damp situations.
The wood of sycamore weighs 35.39 pounds per cubic foot, is hard,
but not strong, difficult to split and work; the annual rings are
limited by narrow bands of dark summerwood. The rings are very
porous. The medullary rays are rather small, but can be easily seen
without a glass. They run in regular, radial lines, close together, and
the pores are in rows between. The rays of sycamore vary from the
rule with most woods, in that they are darker than the body of the
wood.
One of the earliest uses of sycamore was by farmers who cut hollow
trunks, sawed them in lengths of three or four feet, nailed bottoms
in them, and used them for barrels for grain. They were called
gums. Solid logs two or three feet in diameter were cut in lengths of
a foot or less, bored through the center, and used as wheels for ox
carts. The ox yoke was often made of sycamore. Butchers used
sycamore sections about three feet high for meat blocks. The wood
is tough, and continual hacking fails to split it. The use for meat
blocks continues at the present time. In Illinois 1,600,000 feet were
so employed in 1910.
One of the earliest employments of the wood for commercial
purposes was in the manufacture of boxes for plug tobacco; but it
has now been largely replaced by cheaper woods. Its freedom from
stain and odor is its chief recommendation for tobacco boxes. Some
of it is in demand for cigar boxes.
The modern uses of sycamore are many. It is made into ordinary
crates and shipping boxes in most regions where it grows. Rotary cut
veneer is worked into berry crates and baskets, and into barrels. Ice
boxes and refrigerators are among the products. Slack coopers are
among the largest users, but some of the manufactured stave
articles belong more properly to woodenware, such as tubs, washing
machines, candy buckets, and lard pails.
Furniture makers demand the best grades, and most of the quarter-
sawed stock goes to them, though the manufacturers of musical
instruments buy some of the finest. Use is pretty general from pipe
organs and pianos down to mandolins, guitars and phonographs. It
enters extensively into the making of miscellaneous commodities. As
small a toy as the stereoscope consumes much sycamore. Makers of
trunks find it suitable for slats, and it serves as small squares and
borders in parquetry. It is a choice wood for barber poles and saddle
trees, and its fine appearance when worked in broad panels leads to
its employment as interior finish for houses, boats, and passenger
cars.
California Sycamore (Platanus racemosa) is one of the three species of sycamore
now found growing naturally in the United States. They are survivors of a very old
family and appear to have been crowded down from the far North by the cold, or
to have made their way south for some other reason. Sycamores flourished in
Greenland in the Cretaceous age, some millions of years ago, as is shown by fossil
remains dug up in that land of ice and eternal winter. They grew in central Europe,
about the same time, but long ago disappeared from there. Sycamores were
growing in the United States an immense period of time ago, and were doubtless
lifting their giant white branches high above the banks of ancient rivers while the
gorgeous bloom of yellow poplars brightened the forests on the rich bottom lands
farther back. Several species of sycamores which grew in the United States during
the Tertiary age are now extinct. All seem to have been much like those which
have come down to the present day.
The California sycamore is found in the southern half of that state, and in Lower
California. It grows from sea level up to 5,000 feet, and has the same habits as
the larger sycamore of the East, and prefers the banks of streams and the wet
land in the bottoms of canyons. It attains a height of from forty to eighty feet, and
a diameter of from two to five. Some trees are larger, one in particular near Los
Angeles having a trunk diameter of nine feet. The tree is usually extremely
distorted and misshaped, leaning, twisted, and forking and reforking until a
practical lumberman would pronounce it a hopeless proposition. This applies,
however, to trunks which grow in the open, and that is where most of them grow.
When they are found crowded in thick stands in the bottoms of canyons, their
trunks are shapely enough for short sawlogs. The wood is very similar to that of
eastern sycamore, and it is used for similar purposes, when used at all. The balls
are strung five on one tough stem, which is from six to ten inches long. The
eastern sycamore usually has a stem for each ball. The seeding habits of both
trees are the same.
Arizona Sycamore (Platanus wrightii) has its range in southern New Mexico,
southern Arizona, and neighboring regions in Mexico, where it grows in the
bottoms of canyons up to 6,000 feet above sea. The tree attains a height of from
thirty to eighty feet, and a diameter of two to five. The trunk is seldom shapely,
but often divides in large branches, some of which are fifty or sixty feet long.
There are usually three balls on a stem, and the leaf is shaped much like the leaf
of red gum, but there is considerable variation in form. The wood resembles
eastern sycamore in color and most other features, but when quarter-sawed the
flecks produced by the medullary rays are generally smaller, and give a mottled
effect. The wood has not been much used, but apparently it is not inferior to
eastern sycamore.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like