0% found this document useful (0 votes)
11 views89 pages

SQL Server 2000 Stored Procedure Programming Dejan Sunderic Tom Woodhead PDF Download

The document is about 'SQL Server 2000 Stored Procedure Programming' by Dejan Sunderic and Tom Woodhead, detailing various aspects of stored procedure development and programming in SQL Server 2000. It includes chapters on relational database concepts, stored procedure design, debugging, and advanced programming techniques. Additionally, it provides links to related ebooks and resources for further learning.

Uploaded by

cehbremh143
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)
11 views89 pages

SQL Server 2000 Stored Procedure Programming Dejan Sunderic Tom Woodhead PDF Download

The document is about 'SQL Server 2000 Stored Procedure Programming' by Dejan Sunderic and Tom Woodhead, detailing various aspects of stored procedure development and programming in SQL Server 2000. It includes chapters on relational database concepts, stored procedure design, debugging, and advanced programming techniques. Additionally, it provides links to related ebooks and resources for further learning.

Uploaded by

cehbremh143
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/ 89

Sql Server 2000 Stored Procedure Programming

Dejan Sunderic Tom Woodhead download

https://ebookbell.com/product/sql-server-2000-stored-procedure-
programming-dejan-sunderic-tom-woodhead-4107924

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Microsoft Sql Server 2005 Stored Procedure Programming In Tsql Net 3rd
Ed Dejan Sunderic

https://ebookbell.com/product/microsoft-sql-server-2005-stored-
procedure-programming-in-tsql-net-3rd-ed-dejan-sunderic-1307574

Sql Server 2000 Stored Procedures Xml Programming 2nd Edition Dejan
Sunderic

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

Microsoft Sql Server Stored Procedure Programming In Tsql And Dot Net
3rd Edition

https://ebookbell.com/product/microsoft-sql-server-stored-procedure-
programming-in-tsql-and-dot-net-3rd-edition-1278098

Professional Sql Server 2005 Clr Programming With Stored Procedures


Functions Triggers Aggregates And Types Illustrated Edition Derek
Comingore

https://ebookbell.com/product/professional-sql-server-2005-clr-
programming-with-stored-procedures-functions-triggers-aggregates-and-
types-illustrated-edition-derek-comingore-919798
Sql Server 2000 Stored Procedures Handbook 1st Edition Tony Bain

https://ebookbell.com/product/sql-server-2000-stored-procedures-
handbook-1st-edition-tony-bain-11852294

Sql Server 2000 Black Book Patrick Dalton Paul Whitehead

https://ebookbell.com/product/sql-server-2000-black-book-patrick-
dalton-paul-whitehead-51411144

Sql Server 2000 The Complete Reference Jeffrey R Shapiro

https://ebookbell.com/product/sql-server-2000-the-complete-reference-
jeffrey-r-shapiro-4107926

Sql Server 2000 Fast Answers For Dbas And Developers Signature Edition
Joseph Sack

https://ebookbell.com/product/sql-server-2000-fast-answers-for-dbas-
and-developers-signature-edition-joseph-sack-6675620

Sql Server 2000 For Experienced Dbas 1st Edition Brian Knight

https://ebookbell.com/product/sql-server-2000-for-experienced-
dbas-1st-edition-brian-knight-924908
Stored Procedure
Programming
DEJAN SUNDERIC
TOM WOODHEAD

Osborne/McGraw-Hill
Berkeley New York St. Louis San Francisco
Auckland Bogotá Hamburg London Madrid
Mexico City Milan Montreal New Delhi Panama City
Paris São Paulo Singapore Sydney
Tokyo Toronto
Brought to you by ownSky!
Copyright © 2001 by The McGraw-Hill Companies. All rights reserved. Manufactured in the United
States of America. Except as permitted under the United States 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 the publisher.

0-07-213361-9

The material in this eBook also appears in the print version of this title: 0-07-212566-7.

All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after
every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefit
of the trademark owner, with no intention of infringement of the trademark. Where such designations
appear in this book, they have been printed with initial caps.
McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales pro-
motions, or for use in corporate training programs. For more information, please contact George
Hoare, Special Sales, at [email protected] or (212) 904-4069.

TERMS OF USE
This is a copyrighted work and The McGraw-Hill Companies, Inc. (“McGraw-Hill”) and its licensors
reserve all rights in and to the work. Use of this work is subject to these terms. Except as permitted
under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not
decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon,
transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without
McGraw-Hill’s prior consent. You may use the work for your own noncommercial and personal use;
any other use of the work is strictly prohibited. Your right to use the work may be terminated if you
fail to comply with these terms.
THE WORK IS PROVIDED “AS IS”. McGRAW-HILL AND ITS LICENSORS MAKE NO GUAR-
ANTEES OR WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF
OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMA-
TION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE,
AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
PARTICULAR PURPOSE. McGraw-Hill and its licensors do not warrant or guarantee that the func-
tions contained in the work will meet your requirements or that its operation will be uninterrupted or
error free. Neither McGraw-Hill nor its licensors shall be liable to you or anyone else for any inaccu-
racy, error or omission, regardless of cause, in the work or for any damages resulting therefrom.
McGraw-Hill has no responsibility for the content of any information accessed through the work.
Under no circumstances shall McGraw-Hill and/or its licensors be liable for any indirect, incidental,
special, punitive, consequential or similar damages that result from the use of or inability to use the
work, even if any of them has been advised of the possibility of such damages. This limitation of lia-
bility shall apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort
or otherwise.

DOI: 10.1036/0072133619

Terms of Use
Writing a book isn’t easy, but living with someone who is writing
a book can be, at times, even harder. We would like to thank
our respective spouses for their patience,
understanding, and inspiration:
For Mirjana Sunderic and Ann(a) Fricker
AT A GLANCE

▼ 1 Introduction . . . . . . . . . . . . . . . . . . . 1
▼ 2 Relational Database Concepts and the SQL
Server Environment . . . . . . . . . . . . . . 21
▼ 3 Stored Procedure Design Concepts . . . . . . 65
▼ 4 Basic Transact-SQL Programming
Constructs . . . . . . . . . . . . . . . . . . . 105
▼ 5 Functions . . . . . . . . . . . . . . . . . . . . . 167
▼ 6 Composite Transact-SQL Constructs—
Batches, Scripts, and Transactions . . . . . . 223
▼ 7 Debugging and Error Handling . . . . . . . . 269
▼ 8 Developing Professional Habits . . . . . . . . 317
▼ 9 Special Types of Procedures . . . . . . . . . . 345
▼ 10 Advanced Stored Procedure
Programming . . . . . . . . . . . . . . . . . 409
▼ 11 Interaction with the SQL Server
Environment . . . . . . . . . . . . . . . . 465
▼ 12 XML Support in SQL Server 2000 . . . . . . . 527

vii
Terms of Use
viii SQL Server 2000 Stored Procedure Programming

▼ A T-SQL and XML Datatypes in SQL


Server 2000 . . . . . . . . . . . . . . . . . . . 633
▼ B Solutions to the Exercises . . . . . . . . . . . . 641

▼ Index . . . . . . . . . . . . . . . . . . . . . . . 715
CONTENTS

Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii

▼ 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Who Should Read This Book . . . . . . . . . . . . . . . . . . . . . 3
What You Will Find in This Book . . . . . . . . . . . . . . . . . . . 3
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
New Features in SQL Server 2000 . . . . . . . . . . . . . . . . . . . 6
Improved Web Enablement . . . . . . . . . . . . . . . . . . . 7
Improved Scalability and Reliability . . . . . . . . . . . . . . 7
Improved Development and Administration
Environment . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Sample Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Sample Database Installation . . . . . . . . . . . . . . . . . . 9
Purpose and Design of the Sample Database . . . . . . . . . 11
Database Diagram . . . . . . . . . . . . . . . . . . . . . . . . 12
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

▼ 2 Relational Database Concepts and the SQL Server Environment . . . . . 21


Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

ix
Terms of Use
x SQL Server 2000 Stored Procedure Programming

Relational Databases . . . . . . . . . . . . . . . . . . . . . . . 23
Database Objects . . . . . . . . . . . . . . . . . . . . . . . . . 23
What Are Stored Procedures? . . . . . . . . . . . . . . . . . . 32
SQL Server 2000 Tools . . . . . . . . . . . . . . . . . . . . . . . . . 32
Service Manager . . . . . . . . . . . . . . . . . . . . . . . . . 33
Query Analyzer . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Enterprise Manager . . . . . . . . . . . . . . . . . . . . . . . . 36
DTS—Import and Export Data . . . . . . . . . . . . . . . . . 39
osql and isql . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
SQL Server Profiler . . . . . . . . . . . . . . . . . . . . . . . . 41
Client Network Utility . . . . . . . . . . . . . . . . . . . . . . 41
The Help Subsystem and SQL Server Books Online . . . . . 43
Basic Operations with Stored Procedures . . . . . . . . . . . . . . 44
Execution of Stored Procedures from Query Analyzer . . . . 44
Managing Stored Procedures from Enterprise Manager . . . 49
Editing Stored Procedures in Enterprise Manager . . . . . . 54
Editing Stored Procedures in Query Analyzer . . . . . . . . 54
Syntax Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
The Create Stored Procedure Wizard . . . . . . . . . . . . . . 59
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

▼ 3 Stored Procedure Design Concepts . . . . . . . . . . . . . . . . . . . 65


Anatomy of a Stored Procedure . . . . . . . . . . . . . . . . . . . . 66
Composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Types of Stored Procedures . . . . . . . . . . . . . . . . . . . . . . 79
Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
The Compilation and Execution Process . . . . . . . . . . . . 81
Reuse of Execution Plans . . . . . . . . . . . . . . . . . . . . 82
Recompiling Stored Procedures . . . . . . . . . . . . . . . . . 86
Storing Stored Procedures . . . . . . . . . . . . . . . . . . . . 88
Managing Stored Procedures . . . . . . . . . . . . . . . . . . . . . 90
Listing Stored Procedures . . . . . . . . . . . . . . . . . . . . 90
Viewing Stored Procedures . . . . . . . . . . . . . . . . . . . 93
Renaming Stored Procedures . . . . . . . . . . . . . . . . . . 95
Deleting Stored Procedures . . . . . . . . . . . . . . . . . . . 96
Listing Dependent and Depending Objects . . . . . . . . . . 96
The Role of Stored Procedures in the Development of Database
Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Enforcement of Data Integrity . . . . . . . . . . . . . . . . . . 99
Contents xi

Consistent Implementation of Complex Business Rules


and Constraints . . . . . . . . . . . . . . . . . . . . . . . . 99
Modular Design . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Maintainability . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Reduced Network Traffic . . . . . . . . . . . . . . . . . . . . 101
Faster Execution . . . . . . . . . . . . . . . . . . . . . . . . . 101
Enforcement of Security . . . . . . . . . . . . . . . . . . . . . 101
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103

▼ 4 Basic Transact-SQL Programming Constructs . . . . . . . . . . . . . . 105


TSQL Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Database Object Qualifiers . . . . . . . . . . . . . . . . . . . . . . . 110
Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Groups of Datatypes . . . . . . . . . . . . . . . . . . . . . . . 111
Datatype Synonyms . . . . . . . . . . . . . . . . . . . . . . . 123
User-Defined Datatypes . . . . . . . . . . . . . . . . . . . . . 123
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Local Variables . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . 129
Table Variables . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Flow Control Statements . . . . . . . . . . . . . . . . . . . . . . . . 134
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Statement Blocks—Begin … End . . . . . . . . . . . . . . . . 139
Conditional Execution—the If Statement . . . . . . . . . . . 140
Looping—the While Statement . . . . . . . . . . . . . . . . . 145
Unconditional Execution—the GoTo Statement . . . . . . . . 148
Scheduled Execution—the WaitFor Statement . . . . . . . . . 152
Cursors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Transact-SQL Cursors . . . . . . . . . . . . . . . . . . . . . . 154
Cursor-Related Statements and Functions . . . . . . . . . . . 158
Problems with Cursors . . . . . . . . . . . . . . . . . . . . . . 160
The Justified Uses of Cursors . . . . . . . . . . . . . . . . . . 161
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

▼ 5 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Using Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
In Selection and Assignment . . . . . . . . . . . . . . . . . . 168
In Filtering Criteria . . . . . . . . . . . . . . . . . . . . . . . . 169
In Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
As Check and Default Constraints . . . . . . . . . . . . . . . 170
Instead of Tables . . . . . . . . . . . . . . . . . . . . . . . . . 170
xii SQL Server 2000 Stored Procedure Programming

Types of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 172


Scalar Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Aggregate Functions . . . . . . . . . . . . . . . . . . . . . . . 216
Rowset Functions . . . . . . . . . . . . . . . . . . . . . . . . . 218
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221

▼ 6 Composite Transact-SQL Constructs—Batches, Scripts,


and Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Batches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Using Batches . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Batches and Errors . . . . . . . . . . . . . . . . . . . . . . . . 227
DDL Batches . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Database Scripting . . . . . . . . . . . . . . . . . . . . . . . . 236
The Transaction Concept . . . . . . . . . . . . . . . . . . . . . . . . 238
Autocommit Transactions . . . . . . . . . . . . . . . . . . . . 239
Explicit Transactions . . . . . . . . . . . . . . . . . . . . . . . 241
Implicit Transactions . . . . . . . . . . . . . . . . . . . . . . . 243
Transaction Processing Architecture . . . . . . . . . . . . . . 243
Nested Transactions . . . . . . . . . . . . . . . . . . . . . . . 245
Named Transactions . . . . . . . . . . . . . . . . . . . . . . . 251
Savepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Locking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Distributed Transactions . . . . . . . . . . . . . . . . . . . . . 259
Typical Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267

▼ 7 Debugging and Error Handling . . . . . . . . . . . . . . . . . . . . . . 269


Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
What Is a “Bug”? . . . . . . . . . . . . . . . . . . . . . . . . . 270
The Debugging Process . . . . . . . . . . . . . . . . . . . . . 271
Debugging Tools and Techniques . . . . . . . . . . . . . . . 274
Typical Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Using Error Handling . . . . . . . . . . . . . . . . . . . . . . 298
Why Bother? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Tactics of Error Handling . . . . . . . . . . . . . . . . . . . . 300
A Coherent Error Handling Methodology . . . . . . . . . . . 304
XACT_ABORT . . . . . . . . . . . . . . . . . . . . . . . . . . 310
Raiserror . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Contents xiii

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314

▼ 8 Developing Professional Habits . . . . . . . . . . . . . . . . . . . . . 317


The Concept of Source Code Control . . . . . . . . . . . . . . . . . 318
Introduction to Microsoft Visual SourceSafe . . . . . . . . . 319
Administering the Visual SourceSafe Database . . . . . . . . 320
Adding a Database to Visual SourceSafe . . . . . . . . . . . . 322
Managing Stored Procedures . . . . . . . . . . . . . . . . . . 324
Visual SourceSafe Explorer . . . . . . . . . . . . . . . . . . . 328
Naming Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . 334
Why Bother? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
Naming Objects and Variables . . . . . . . . . . . . . . . . . 335
Suggested Convention . . . . . . . . . . . . . . . . . . . . . . 338
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343

▼ 9 Special Types of Procedures . . . . . . . . . . . . . . . . . . . . . . . 345


Types of Stored Procedures . . . . . . . . . . . . . . . . . . . . . . 346
User-Defined Stored Procedures . . . . . . . . . . . . . . . . 346
System Stored Procedures . . . . . . . . . . . . . . . . . . . . 346
Extended Stored Procedures . . . . . . . . . . . . . . . . . . 348
Temporary Stored Procedures . . . . . . . . . . . . . . . . . 357
Global Temporary Stored Procedures . . . . . . . . . . . . . 358
Remote Stored Procedures . . . . . . . . . . . . . . . . . . . . 358
User-Defined Functions . . . . . . . . . . . . . . . . . . . . . . . . 359
Design of User-Defined Functions . . . . . . . . . . . . . . . 359
Table-Valued User-Defined Functions . . . . . . . . . . . . . 364
In-Line Table-Valued User-Defined Functions . . . . . . . . 368
Managing User-Defined Functions in Enterprise Manager . . 371
Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
Physical Design . . . . . . . . . . . . . . . . . . . . . . . . . . 374
Handling Changes on Multiple Records . . . . . . . . . . . . 382
Nested and Recursive Triggers . . . . . . . . . . . . . . . . . 384
Trigger Restrictions . . . . . . . . . . . . . . . . . . . . . . . . 385
Triggers in SQL Server 2000 . . . . . . . . . . . . . . . . . . . 386
Managing Triggers . . . . . . . . . . . . . . . . . . . . . . . . 391
Trigger Design Recommendations . . . . . . . . . . . . . . . 395
Transaction Management in Triggers . . . . . . . . . . . . . 398
Using Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . 399
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408
xiv SQL Server 2000 Stored Procedure Programming

▼ 10 Advanced Stored Procedure Programming . . . . . . . . . . . . . . . . 409


Dynamically Constructed Queries . . . . . . . . . . . . . . . . . . 410
Executing a String . . . . . . . . . . . . . . . . . . . . . . . . 410
Query By Form . . . . . . . . . . . . . . . . . . . . . . . . . . 412
Using the sp_executesql Stored Procedure . . . . . . . . . . 415
Optimistic Locking Using Timestamps . . . . . . . . . . . . . . . . 417
Timestamp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
TSEQUAL Function . . . . . . . . . . . . . . . . . . . . . . . 420
Timestamp Conversion . . . . . . . . . . . . . . . . . . . . . 422
Full Text Search and Indexes . . . . . . . . . . . . . . . . . . . . . 425
Nested Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . 427
Using Temporary Tables to Pass a Recordset to a Nested
Stored Procedure . . . . . . . . . . . . . . . . . . . . . . . 433
Using a Cursor to Pass a Recordset to a Nested
Stored Procedure . . . . . . . . . . . . . . . . . . . . . . . 437
How to Process the Resultset of a Stored Procedure . . . . . . . . 440
Using Identity Values . . . . . . . . . . . . . . . . . . . . . . . . . . 447
A Standard Problem and Solution . . . . . . . . . . . . . . . 447
Identity Values and Triggers . . . . . . . . . . . . . . . . . . 449
Sequence Number Table . . . . . . . . . . . . . . . . . . . . . 450
Preserving an Identity Value in a Temporary Table . . . . . 453
GUIDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
A While Loop with MIN or MAX Functions . . . . . . . . . . . . . 457
Property Management . . . . . . . . . . . . . . . . . . . . . . . . . 460
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463

▼ 11 Interaction with the SQL Server Environment . . . . . . . . . . . . . 465


Execution of OLE Automation Objects . . . . . . . . . . . . . . . . 466
sp_OACreate . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
sp_OAMethod . . . . . . . . . . . . . . . . . . . . . . . . . . 470
sp_OASetProperty . . . . . . . . . . . . . . . . . . . . . . . . 471
sp_OAGetProperty . . . . . . . . . . . . . . . . . . . . . . . . 471
sp_OADestroy . . . . . . . . . . . . . . . . . . . . . . . . . . 472
sp_OAGetErrorInfo . . . . . . . . . . . . . . . . . . . . . . . . 472
Datatype Conversion . . . . . . . . . . . . . . . . . . . . . . . 472
Running Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
Running Windows Script Files . . . . . . . . . . . . . . . . . . . . 475
Interacting with the NT Registry . . . . . . . . . . . . . . . . . . . 475
Registry Subtrees . . . . . . . . . . . . . . . . . . . . . . . . . 475
Keys and Subkeys . . . . . . . . . . . . . . . . . . . . . . . . 476
The Registry and SQL Server . . . . . . . . . . . . . . . . . . . . . 477
xp_regread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
Contents xv

xp_regwrite . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
xp_regdeletevalue . . . . . . . . . . . . . . . . . . . . . . . . 480
Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480
Administration of Jobs . . . . . . . . . . . . . . . . . . . . . . 481
Alternative to Job Scheduler . . . . . . . . . . . . . . . . . . . 486
Stored Procedures for Maintaining Jobs . . . . . . . . . . . . 487
Operators and Alerts . . . . . . . . . . . . . . . . . . . . . . . 488
SQL Server and the Web . . . . . . . . . . . . . . . . . . . . . . . . 489
Web Assistant . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
Web Task Stored Procedures . . . . . . . . . . . . . . . . . . 494
sp_makewebtask . . . . . . . . . . . . . . . . . . . . . . . . . 495
sp_runwebtask . . . . . . . . . . . . . . . . . . . . . . . . . . 496
sp_dropwebtask . . . . . . . . . . . . . . . . . . . . . . . . . 496
Web Page Templates . . . . . . . . . . . . . . . . . . . . . . . 497
String Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
xp_sprintf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
xp_sscanf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
Mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
Extended Stored Procedures for Work with E-Mail . . . . . 501
xp_sendmail . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
xp_readmail . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
sp_processmail . . . . . . . . . . . . . . . . . . . . . . . . . . 504
Database Deployment . . . . . . . . . . . . . . . . . . . . . . . . . 505
A Long Time Ago, in an Environment Not So Far
Away… . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
Now . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506
Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508
Security Architecture . . . . . . . . . . . . . . . . . . . . . . . 508
Implementing Security . . . . . . . . . . . . . . . . . . . . . . 512
Synchronization of Login and User Names . . . . . . . . . . 519
Managing Application Security Using Stored Procedures,
User-Defined Functions, and Views . . . . . . . . . . . . . 520
Managing Application Security Using a Proxy User . . . . . 523
Managing Application Security Using Application Roles . . . 524
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526

▼ 12 XML Support in SQL Server 2000 . . . . . . . . . . . . . . . . . . . . 527


XML (R)evolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528
Introduction to XML . . . . . . . . . . . . . . . . . . . . . . . . . . 530
Introduction to Markup Languages . . . . . . . . . . . . . . 530
Building Blocks of Markup Languages . . . . . . . . . . . . . 531
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
xvi SQL Server 2000 Stored Procedure Programming

XML Document Quality . . . . . . . . . . . . . . . . . . . . . 538


XML Parsers and DOM . . . . . . . . . . . . . . . . . . . . . 545
Linking and Querying in XML . . . . . . . . . . . . . . . . . 546
Transforming XML . . . . . . . . . . . . . . . . . . . . . . . . 552
Why XML? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554
Exchange of Information Between Organizations . . . . . . . 555
Information Publishing . . . . . . . . . . . . . . . . . . . . . 557
XML Support in SQL Server . . . . . . . . . . . . . . . . . . . . . . 557
Transact-SQL Language Extensions . . . . . . . . . . . . . . 557
OPENXML . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
Publishing Database Information Using XML . . . . . . . . . 590
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 630

▼ A T-SQL and XML Datatypes in SQL Server 2000 . . . . . . . . . . . . . . 633

▼ B Solutions to the Exercises . . . . . . . . . . . . . . . . . . . . . . . . 641

▼ Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715
ACKNOWLEDGMENTS

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

—Margaret Abbott, who helped in the preparation of about


three quarters of the text

—Liang Wang, who showed us just how easy it really is to


write extended stored procedures and who subsequently
reviewed that portion of the book

—Snezana Milivojevic, who showed us the error of our ways


in Chapter 7

—Gerry Kichok, who reviewed our rendering of SQL Server’s


XML capabilities in Chapter 12

xvii
CHAPTER 1
Introduction

1
Terms of Use
Brought to you by ownSky!
2 SQL Server 2000 Stored Procedure Programming

W
elcome to SQL Server 2000 Stored Procedure Programming.
This book identifies and describes the key concepts,
techniques, tips, tricks, and habits 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 we 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
Chapter 1: Introduction 3

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 RDBMS of choice for
mission-critical application development, the need for more advanced
work on SQL Server stored procedures becomes even more critical.

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 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 concepts and methods.
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 make you an accomplished professional.
We 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


All chapters in this book (aside from the one you are reading, which
is introductory in nature) provide conceptual grounding in a specific
area of the SQL Server development landscape. Chapters 3 through 12
go beyond this conceptual grounding to provide the techniques and
4 SQL Server 2000 Stored Procedure Programming

examples to help you realize the concepts within the SQL Server
development environment. Chapters 2–7 and 9–12 contain exercises
designed to help you apply and develop the skills learned in the
chapter. You can find the solutions to the exercise in Appendix B,
“Solutions.”
Chapter 1, “Introduction,” describes the content of this book, as
well as its intended audience, and introduces you to new features
available in SQL Server 2000. It also describes a sample database that
we will use throughout the book to demonstrate stored procedure
development.
Chapter 2, “Relational Database Concepts and the SQL Server
Environment,” provides a 30,000-foot overview that will help you
establish a conceptual grounding in relational database management
systems (RDBMSs) in general, and in SQL Server architecture in
particular. It will briefly introduce 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.
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
datatypes, 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, “Developing Professional Habits,” discusses the work
habits that differentiate the professional DBA from the amateur,
particularly source code control and the use of naming conventions.
Chapter 1: Introduction 5

Chapter 9, “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, and instead-of triggers.
Chapter 10, “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 11, “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 12, “XML Support in SQL Server 2000,” first introduces
XML as the markup language of choice for information exchange and
publishing and then focuses on specific features in SQL Server 2000
that you can use to tackle XML.
Appendix A, “T-SQL and XML Datatypes in SQL Server 2000,”
provides you with three tables that list datatypes in use in SQL
Server 2000 and the way they map.
Appendix B, “Solutions to the Exercises,” provides users with
solutions for the exercises that accompany the chapters.

REQUIREMENTS
To make full use of this book, you will need access to a server
running one of the following versions of SQL Server:

▼ 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 4 CPUs and 2GB RAM)
▲ Evaluation Edition (supports all features of Enterprise
Edition; use is limited to 120-days; available for download
over the Web)
6 SQL Server 2000 Stored Procedure Programming

However, you can also perform most of the 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 2 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)

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.
We recommend that you obtain some other version (such as the
Evaluation Edition).

NEW FEATURES IN SQL SERVER 2000


SQL Server 2000 continues the design philosophy first extolled in
version 7.0 and presents advances over previous versions in the
following areas:

▼ Improved Web enablement


■ Improved scalability and reliability
▲ Improved development environment (faster time to market,
lower Total Cost of Ownership)
Chapter 1: Introduction 7

Improved Web Enablement


If you are a database or Web developer, you will find SQL Server
2000’s implementation of XML both invaluable and easy to use.
The addition of XML capability means that you will be able to
interchange data and publish database information using XML.
SQL Server 2000 also supports secure data access from a browser
through firewalls, full-text searches of formatted documents (HTML,
XML), and “English” (plain language) queries.
SQL Server 2000 Analytical Services include Online Analytical
Processing (OLAP) Server as well as a set of data-mining tools to
allow complete integration with Microsoft Commerce Server and
provide complete click-stream and Web data analysis (also known
as Business Internet Analytics).

Improved Scalability and Reliability


SQL Server is the Web’s most popular database solution because
Web-based e-commerce requires rapid and seamless scalability. It
supports scaling up (to a more powerful server), scaling out (to
more servers working concurrently) and scaling down (to nonserver
operating systems such as Windows 2000 Professional, Windows NT
Workstation, Windows ME, Windows 98, or even Windows CE).
When coupled with Windows 2000, SQL Server 2000 (Enterprise
Edition) provides support for Symmetric Multiprocessing (SMP), so
you can take advantage of up to 32 CPUs and 64 gigabytes of RAM.
It can run different parts of a query on different CPUs in parallel,
thus increasing the speed with which results are returned. The query
optimizer uses hash and merge algorithms to improve join operations.
SQL Server 2000 provides the ability to horizontally partition
workloads across multiple SQL Server installations. A group of
federated database servers can share horizontally partitioned data. They
can be (indeed, they have to be) managed independently, but they
will share the workload of application requests.
Simplified configuration of fail-over clustering means that it is
easier to maximize the availability of your database. You can even
perform most maintenance tasks while your database remains online.
8 SQL Server 2000 Stored Procedure Programming

SQL Server 2000 has many improvements that support Very


Large Databases (VLDB):

▼ Performance of backup and restore operations is significantly


improved.
■ Bulk copy operations can be performed in parallel on the
same table.
■ Multiple indexes can be performed at the same time.
▲ It now supports terabyte databases.

All these improvements make SQL Server 2000 an ideal choice for
intensive line-of-business (LOB) and data warehousing solutions.

Improved Development and Administration Environment


The speed with which the Web is driving the development of today’s
applications makes “time to market” a key factor in judging any
development environment or effort. SQL Server 2000’s improved
ease of use helps you build, deploy, and manage your databased
applications—whether for e-commerce, line-of-business, or data
warehousing—more quickly and confidently than ever before.
SQL Server 2000 simplifies and automates performance tuning
and monitoring, and it simplifies the movement of databases
between instances of SQL Server. It works in conjunction with the
Windows 2000 Active Directory service to allow centralized database
management. It configures itself while running, automatically and
dynamically, for optimal performance in an ever-changing
environment. Intervention by an experienced DBA is possible but
not required.
The new integrated T-SQL debugger, T-SQL templates, “instead-of”
triggers, and user-defined functions will reduce development time
considerably.
Chapter 1: Introduction 9

Microsoft’s integration of Data Transformation Services (DTS)


with Microsoft Message Queue Server (MSMQ) means that DTS can
now access information over the Internet via FTP.

SAMPLE DATABASE
We have created a sample database that we will use through most
of this book. The subject of the Asset sample database 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 inter-
department 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/sp_book.htm.
2. Click the link to the database on the screen. When prompted,
opt to save the file to disk. Remember the location to which
you saved the file.
10 SQL Server 2000 Stored Procedure Programming

3. Unzip the contents of the zip file into the \Program


Files\Microsoft SQL Server\MSSQL\Data folder of the
machine on which SQL Server is installed.
4. 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:

5. Run Query Analyzer (select Programs | MS SQL Server |


Query Analyzer).
6. 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 (i.e.,
an empty string):

Query Analyzer opens a query window pointing to the master


database:
Chapter 1: Introduction 11

7. Type the following text in the query window:


EXEC sp_attach_db 'Asset',
E:\Program Files\Microsoft SQL Server\MSSQL\Data\Asset_data.mdf
E:\Program Files\Microsoft SQL Server\MSSQL\Data\Asset_log.ldf

If the location of the folder containing the Asset database file


is different from the one shown in the command, change the
command.
8. To attach the database, select Query | Execute from the menu
bar. SQL Server attaches the database. The database is now
ready for use.

Purpose and Design of the Sample Database


The Asset database is designed to track and manage assets within an
organization. This database allows users to

▼ Track features of assets


■ Search for assets with specific features
■ Record the current location and status of an asset
12 SQL Server 2000 Stored Procedure Programming

■ Track the person and organizational unit to which the asset


is assigned
■ Note how an asset is acquired and the cost of the acquisition
■ Keep parameters concerning leases (e.g., lease payments, lease
schedules, lease vendors used to obtain assets)
■ Identify assets for which lease schedules have expired
■ Record orders to departments in charge of services such as
acquisition, disposal, servicing, and technical support
■ Monitor the processing of orders
▲ Manage the costs associated with actions taken on order items

Database Diagram
Figure 1-1 shows the physical implementation of the Asset entity
relationship diagram.

Description of Assets
The following illustration shows the tables involved in the
description of each asset. Detailed information about deployed
equipment and their features is essential for the proper management
of current inventory as well as future upgrades and acquisitions.
Chapter 1: Introduction 13

Figure 1-1. A database diagram of the Asset database

Information in these asset description tables allows users to

▼ Manage a list of standard equipment deployed within the


organization
■ Manage a list of attributes (properties) that can be used to
describe assets
■ Manage a list of attributes for each asset
■ Obtain a summary of equipment deployed within the
organization
■ Make decisions about the deployment of a software package
based on the capabilities of existing equipment in the field
▲ Find obsolete pieces of equipment that need to be disposed
of and replaced with new equipment
14 SQL Server 2000 Stored Procedure Programming

Inventory The central table in the Asset database is the Inventory


table. It is designed to track the assets currently deployed within an
organization. The most important information about an asset indicates
what kind of equipment it is. This table also stores information about
the asset’s current location and its status, as well as the way in which
the asset was acquired and the cost of acquisition.

Equipment The Equipment table stores the make and model of


each type of asset. Each piece of equipment with a unique make and
model has a separate record in this table. It groups equipment by
equipment type. To accommodate SOUNDEX search (and illustrate
the use of this SOUNDEX function), the Equipment table also has a
field for precalculated SOUNDEX codes representing the makes and
models of equipment.

EqType This table lists types of equipment. For example, equipment


types include notebook, printer, monitor, keyboard, mouse, scanner,
and network hub.

Properties Each asset in the database can be described with a set of


attributes listed in the Properties table. This table also records a unit
used to store the value of the property. For example, the properties
(and units) of a monitor are size (inch), resolution (pixel), type (n/a),
while an external hard disk has properties (and units) such as capacity
(GB), size (inch), and adapter (n/a).

InventoryProperty Each Asset in the Inventory table has a set of


properties. The InventoryProperty table stores the values of each
property (except for make and model, which are recorded in the
Equipment table).
For example, a Toshiba (Make) Protégé 7020 (Model) notebook
(EqType) assigned to an employee has 64 (value) MB (unit) of RAM
(property) and 4.3 (value) GB (unit) of HDD capacity (property) and
a Pentium II 333 (value) processor (property), and so on. Another
employee is using an upgraded version of the same equipment
with 128 (value) MB (unit) of RAM (property) and 6.4 (value) GB
(unit) of HDD capacity (property) and a Pentium II 366 (value)
processor (property), and so on.
Chapter 1: Introduction 15

Deployment of Assets
This set of tables keeps track of the location in which an asset is
deployed and the person and organizational unit to which the asset
is assigned:

The information in these asset deployment tables allows users to

▼ Manage a list of locations within an organization


■ Manage a list of persons working within an organization
■ Retrieve contact information about persons to whom assets
are assigned
■ Generate reports about assets deployed by province and
organizational unit
■ Retrieve a list of assets assigned to a particular person
■ Manage relationships between organizational units
▲ Assign person(s) to organizational units

Location The Location table stores information about the physical


location of the deployed asset. Each location has a name and an
address as attributes.
16 SQL Server 2000 Stored Procedure Programming

Province This table contains a list of provinces and states. The


primary key is the abbreviation of the province/state. The presence
of this table is essential for reports, which will aggregate asset
deployment by location, province/state, and country.

Contact This table contains a list of persons involved in the asset


management process. It includes persons with assets assigned to
them, persons completing and approving orders, and persons
performing maintenance and support.

Organizational Unit Each contact is assigned to some organizational


unit within the organization. The OrgUnit table records relationships
between companies, cost centers, departments, and the like. This
table is designed as a recursive table: an organizational unit can be
part of some other organizational unit. This quality also reflects the
need for rapid changes in today’s work environment due to change
of ownership, restructuring, and so on.

Leasing Tables
An important aspect of asset management is the tracking of lease
information. It helps management avoid payment of penalties
associated with late returns or the failure to return leased assets
to the leasing vendor:
Chapter 1: Introduction 17

The information in the lease tables allows users to

▼ Keep track of the assets associated with each lease


■ Manage lease schedules to keep track of start, end, and
duration of lease periods
■ Identify assets that need to be returned to a lease vendor
■ Generate reports on assets deployed by lease schedule and
lease contract
■ Retrieve a list of assets obtained from a particular lease
vendor
▲ Retrieve the total value of lease payments, lease schedules,
and lease contracts

Lease The Lease table contains information about lease contracts. It


records the name of the lease vendor, the number of the lease that the
vendor is using to track the contract, the date the contract was signed,
and the total value of assets assigned to the lease.

Lease Schedule Assets obtained through one lease contract might not
be received on the same date. An asset might also be under a different
payment regime and lease duration. Therefore, each lease contains a
set of lease schedules. Each schedule is recorded in the LeaseSchedule
table and is described with a start date, an end date, and the frequency
of payments. This table also tracks the total value of payments per
lease term.

Lease Frequency LeaseFrequency is a lookup table that contains all


possible values for lease frequency including monthly, semimonthly,
biweekly, and weekly.

Acquisition Type AcquisitionType is a lookup table that lists possible


acquisition types including lease, purchase, and rent.

Order Tables
Orders are the primary means of managing assets within the
organization. Users can request new assets and the disposal of
obsolete assets. They can request maintenance and technical support.
18 SQL Server 2000 Stored Procedure Programming

Authorized personnel can monitor orders and react to them,


associate a cost with their execution, and generate invoices. The
following tables are used to store information about orders:

The information in these order tables allows users to

▼ Request new equipment


■ Request technical support
■ Request maintenance
■ Execute scheduled maintenance
■ Track the status of orders
■ Assign a staff member to execute the order
■ Approve the execution of orders
■ Manage a list of actions and the default costs associated
with them
■ Track costs associated with each activity
■ Generate interdepartmental invoices
Chapter 1: Introduction 19

■ Request the transfer of assets


■ Request the disposal of obsolete assets
▲ Generate summaries and reports on performed activities

Orders Users can record requests in the Order table. At that time, the
order date and target date are recorded. General request requirements
are recorded as an order type, and special requirements are recorded
as a note. The person making the request is recorded, as well as the
person approving the request and assigning the order for execution.
If the order is a transfer request, the table also records a destination
for the asset. Users can track the status of the order, and once it is
completed, its completion date is set. At that point, one organizational
unit is billed for performed actions, and once the order is paid, the
payment is noted on the order and funds are assigned to the
organizational unit completing the order.

Order Items The OrderItem table records assets that need the
intervention of authorized personnel or new equipment that needs
to be purchased. Special requests are recorded in the Note field.

Actions The Action table manages the list of activities needed to


complete a request as well as the default cost associated with each.

Charge Log Actions performed on an order item to complete an


order will be recorded in the ChargeLog table. This table will be
used to generate an invoice after completion of the order.

Order Status The OrderStatus table is used as a lookup table to


manage the status of orders. It contains statuses such as

▼ Ordered
■ In-process
■ Canceled
■ Deferred
▲ Completed
20 SQL Server 2000 Stored Procedure Programming

Order Types The OrderType table is used as a lookup table to store


the general requirements of the order. It contains values such as

▼ Requisition
■ Transfer
■ Support
■ Scrap
▲ Repair

Activity Log This table is not related specifically to the recording of


orders. Rather, it is a repository for audit trail information. Most of
the time it is populated by a trigger associated with some specific
database change.

SUMMARY
This chapter has provided all the information you need to use this
book effectively. It has shown that the integration capability, ease
of use, flexibility, and power of Microsoft SQL Server make it the
relational database management system of choice for business
organizations and application developers, and it has shown how the
enhancements in SQL Server 2000 can help those organizations and
developers meet today’s technological and business challenges.
We have identified the intended audience for this book and the
types and locations of information that individuals within that
diverse audience can find in this book.
After reading this chapter, you should also have an understanding
of the resources you will require to proceed in your quest to become
an accomplished professional in the development and use of stored
procedures.
Lastly, this chapter describes the sample database that we have
made available to you via the Web. The sample database includes
most of the examples used in this book and is essential to the effective
use of this book and the successful completion of the exercises
provided at the end of each chapter.
CHAPTER 2
Relational Database
Concepts and the
SQL Server
Environment

21
Terms of Use
22 SQL Server 2000 Stored Procedure Programming

Y
ou already know that SQL Server is a full-featured and
powerful database management system. You may also be
experienced in some or many aspects of this system. But
before you proceed to become an expert in application development
using SQL Server stored procedures, we should probably take a step
back and look at the “big picture” to ensure that we share the same
conceptual grounding.
To attain this conceptual grounding, we will start with a 30,000-ft.
overview that will cover the following topics:

▼ Relational database systems and the objects that


compose them
■ SQL Server architecture
■ A brief discussion of the Transact-SQL language
■ A brief introduction to SQL Server tools
▲ A quick overview of stored procedure design

This overview will be concise. It will not be the only resource


you need to develop a full understanding of the ways and means of
SQL Server database development. It will bring the big picture into
focus, identify the components of that big picture, and describe the
relationships between those components. It will serve to highlight
any gaps that may exist in your knowledge, but it will be too dull
an instrument to eliminate those gaps if they are too large or too
pronounced.
I have written this overview to enable people in a hurry to learn
the basics and then get down to working with stored procedures
and building killer applications. I am going to assume that you have
already had an opportunity to work with SQL Server, or some other
database system, and that you understand common database
concepts. The real purpose of this overview is to define the
terminology that we will use as the foundation on which to build
your knowledge of programming in the SQL Server environment. I
will direct you to other books published by Osborne/McGraw-Hill
Chapter 2: Relational Database Concepts and the SQL Server Environment 23

that will help to develop your knowledge of related SQL Server


conceptual and development topics:

▼ SQL Server 2000: A Beginner’s Guide by Dušan Petkovic


▲ SQL Server 2000 Design & TSQL Programming by Michelle
Poolet and Michael D. Reilly

DATABASES
People often use the term “database” to describe what are really two
different types of objects. The term can be associated with a physical
or virtual structure used to store and manage information. It does
not even matter whether it is implemented on a computer in the form
of one kind of file or another, or as a set of index cards in a library.
In both cases, we refer to the structure used to store information
as a database.
The same word can be used in reference to a system that is used
to access information and manage database storage. Of course, this
usage implies that such a system is implemented as computer
software. This type of database is often called a relational database
management system (RDBMS). Depending on the implementation,
an RDBMS can also be labeled a database server.

Relational Databases
One way to implement a database system on a computer is based on
the concept of a relational database system. Such databases implement
ideas first described by Codd and Date in the early 1970s. They took
the name from a mathematical concept known as a relation, which is
an ordered set of values from different domains.

Database Objects
Data and programs in SQL Server are organized into logical
components called database objects. Database users (administrators
24 SQL Server 2000 Stored Procedure Programming

and developers) access and manage information in SQL Server by


accessing and managing database objects.

NOTE: If you have worked with or are familiar with some object-oriented
programming language or methodology, let me warn you that database
objects will not comply with the definitions found in such languages.

Tables
As with any other relational database system, the most important
database objects in SQL Server are tables. Data in SQL Server is
organized in tables, which consist of rows and columns. You can
visualize SQL Server tables by thinking of the two-dimensional
tables you find in spreadsheet applications such as Microsoft Excel.
Usually, a table represents entities such as persons, assets, or
locations. A row in a table corresponds to one instance of an entity
(for example: one person, or one asset, or one location). Each column
contains an attribute that describes some aspect of the entity. For
example, a person can be described with columns representing
first name, last name, date of birth, phone number, and other such
characteristics.
The major difference between tables that comply with the
relational database concept and other types of tables is that the data
in a column must describe only one attribute. All values in a column
must belong to only one domain of appropriate values. An ordered
set of values that belong to different domains is called a relation. The
collection of column definitions and other table attributes (constraints)
belongs to a table definition. This information is often called metadata
information—data about data.
There are many types of table and column attributes. Constraints
are database objects used to enforce rules that values in columns
must follow to be written to the database. Database designers can use
them to specify default values, to point to a list of allowed values, or
to specify a rule that needs to be satisfied. Datatypes are objects that
specify the type of data (number, character, dates, and so on) that can
be stored in a column.
Chapter 2: Relational Database Concepts and the SQL Server Environment 25

Databases
Sets of tables in SQL Server belong to databases. A database is an
object that contains all other objects. It is stored physically in one or
more database files, but SQL Server manages storage issues so that
users do not have to be concerned with the database files themselves.
Tables stored in the database can be categorized by functionality
into two groups: user tables and system tables. User tables store
application information—information about entities that database
users are interested in. System tables store metadata information such
as lists of database objects, object definitions, and database security
information. There are also several system databases, which contain
server metadata information such as the locations of other databases,
definitions of maintenance tasks, configuration parameters of the
server, and server security information.

Transact-SQL Statements
RDBMS systems include special applications that enable users to
issue statements to retrieve and change information concerning
entities.

Query Statements Most database applications allow the user to issue


a query statement and view a resultset that contains the requested
information, or to issue a change statement and receive a confirmation
that the operation was successful. All mainstream database systems
use the same standard language—SQL (Structured Query Language)—
to describe the resultset that users want to receive from the database
system. Microsoft SQL Server uses a dialect of SQL known as
Transact-SQL or TSQL. All SQL dialects use the following four
basic SQL statements: Select, Insert, Update, and Delete.
The most important Transact-SQL statement is the Select
statement. It is used to describe the resultset the user wants to
retrieve from the database system. The Insert statement is used to
move information into tables. The purpose of the Update statement
is to change information that is already stored in tables within
the database. The Delete statement is used to remove records
from tables.
26 SQL Server 2000 Stored Procedure Programming

The following statement will list all records in the Customers table:
select * from Customers

The major difference between statements in Transact-SQL and


those in other programming languages is that Transact-SQL
statements describe what needs to be displayed (retrieved) or
changed, but not how to do it. Thus, Transact SQL is known as
a nonprocedural language.

DDL Statements Transact-SQL also contains a huge set of statements


designed to create and manage database objects and other metadata
information. This subset of statements is often referred to as the Data
Definition Language (DDL).
The following statement will create a Customers table that
contains six columns:
Create table Customers (CustomerId int,
CustomerName varchar(50),
Address varchar(50),
City varchar(50),
Phone varchar(50),
Fax varchar(50))

Each column definition also indicates the type of data the column
will store.

Groups of Statements Transact-SQL statements are usually issued


in groups. A script is a set of SQL statements organized into a file.
Scripts are generally created to run complex or repetitive operations
such as the creation of a report, the transfer of funds from one
account to another, or some database maintenance activity. A user
may wish to write such a set of statements to a file for later reuse.
A batch is a group of one or more Transact-SQL statements that is
sent to the server simultaneously. When the server receives a batch,
it parses it, compiles it into an execution plan, and finally executes it.
Chapter 2: Relational Database Concepts and the SQL Server Environment 27

Transact-SQL Statements Organized in Database Objects Transact-SQL


statements can also be grouped and stored in the database.
Views are database objects that behave like virtual tables. They are
implemented as stored Select statements.
A stored procedure is a database object designed to store, for later
use, a group of Transact-SQL statements that describes how some
operation should be carried out. Database users (administrators and
developers) can create user-defined stored procedures. SQL Server is
delivered with a set of system-stored procedures, which cover all
aspects of managing data, objects, and the server.
A trigger is a special type of procedure attached to tables and
executed when a predefined change is performed on the table.
A function is a database object that returns a single value. Some
functions are implemented as a set of Transact-SQL statements,
and others are implemented as built-in functions for returning a
particular value to the caller.

Other Objects
Many other objects are also treated as database objects. Logins are
account identifiers that allow users to be recognized by SQL Server.
After users are identified, SQL Server allows them access to the
databases they are authorized to use. Their logins must be recognized
as users (another object) in those databases. Developers can create
diagrams of tables stored in a database. Administrators can create jobs
that are going to perform some business or maintenance operation at
a scheduled time or on demand.

Client/Server Architecture
Database users often work with specialized applications to view
and modify the data in a database. Such applications are often
called client applications, client tools, front-end applications, or database
applications. All of these terms are descriptive of the architecture of
such a system.
28 SQL Server 2000 Stored Procedure Programming

A client/server system consists of two or more programs or systems


that interact to provide a user with required information or help a
user to perform some action. The client application makes a request,
and the server program fulfills the request:

In the SQL Server environment, requests take the form of


Transact-SQL statements. SQL Server processes them and returns a
resultset to the client application with the required information or
just a confirmation that the action was performed successfully. Many
client applications or users can make requests concurrently, and SQL
Server is capable of processing them in parallel.
A client application can offer a different level of comfort to a
user. The simplest tools (but not the easiest to use) allow a user to
enter a request in the form of a Transact-SQL statement and receive
Chapter 2: Relational Database Concepts and the SQL Server Environment 29

resultsets in the form of text or a table. More sophisticated tools


have forms, reports, and other user-friendly screen objects.
To physically establish a connection with a database server and
transfer requests and resultsets, client applications can use different
data access objects or data access APIs. The most common such objects
are ADO (ActiveX Database Objects), RDO (Remote Database
Objects), DB-Library, ODBC, OLE DB, and DAO (Database Access
Objects). Application developers use these objects, or APIs, to access
database objects and data stored in them and to develop client
applications in programming languages such as Visual Basic, Java,
ASP, C, and C++.
This system architecture is the simplest one. The client side of
such a system contains a user interface, presentation services, business
services (the part of the application that implements business rules),
and data servicess (the part of the system responsible for accessing the
data storage). Data storage (usually a database) is located on the
server. Since the components of the system are stored in two
tiers—one on a workstation and the other on a server—this
architecture is often called two-tier architecture. Because the business
logic in this case is stored on the client side (workstation), this
variation of two-tier architecture is often called fat client architecture:
30 SQL Server 2000 Stored Procedure Programming

Unfortunately, such systems have many performance, security,


deployment, and management issues. Some of these issues can be
resolved by implementing part of the business services on the
server—for example, in the form of stored procedures. Such
architecture is sometimes called fat server or two-and-a-half-tier
architecture:

To further improve the system, application architects can use


three-tier architecture, in which data, business, and presentation
services are strictly divided into different components, or tiers:
Chapter 2: Relational Database Concepts and the SQL Server Environment 31

It is also possible to further divide application services, in which


case it is called multitier or n-tier architecture:

This architecture is especially convenient for Web applications,


since such applications must be able to scale to thousands of users,
and deployment and management requirements on such a level
are very strict. The following diagram shows one variant of such
architecture:
32 SQL Server 2000 Stored Procedure Programming

What Are Stored Procedures?


Stored procedures are database objects that encapsulate collections
of Transact-SQL statements on the server for later repetitive use.
Although stored procedures use nonprocedural Transact-SQL
statements, they are in essence procedural. They define algorithms
that determine how operations should be performed.
Stored procedures are the TSQL equivalents of subroutines in
other programming languages. Developers of custom database
applications can use all major programming constructs while
building stored procedures:

▼ Variables
■ Datatypes
■ Input/output parameters
■ Return values
■ Conditional execution
■ Loops
▲ Comments

SQL Server includes a set of system stored procedures designed for


administering the system. Their role is to provide information, set
configuration, control the environment, manage user-defined objects,
and schedule and run custom tasks.

SQL SERVER 2000 TOOLS


All versions of SQL Server except SQL Server 2000 Desktop Engine
(or MSDE) are delivered with the following management tools:

▼ Service Manager
■ Enterprise Manager
■ Query Analyzer
■ DTS—Import/Export Data
Chapter 2: Relational Database Concepts and the SQL Server Environment 33

■ osql
■ isql
■ Profiler
▲ Client Network Utility

Service Manager
The SQL Server database server is implemented as the following
services:

▼ MSSQLServer
■ SQLServerAgent
■ MSDTC
▲ SQL Mail and SQLAgentMail

The RDBMS is actually implemented as the MSSQLServer service.


It receives queries from users, executes them, sends responses to
calling applications, and manages data in database files.
SQLServerAgent is an automation service that manages the
scheduled execution of tasks and notifies administrators of problems
that occur on the server.
MSDTC (Microsoft Distributed Transaction Coordinator) is a service
that manages two-phase commit transactions spanned over multiple
servers. This service ensures that changes that need to be made to
data stored on different servers complete successfully.
SQL Mail is used to send and receive e-mail. It is possible to
configure SQL Server to perform such tasks as receiving requests
and returning resultsets through e-mail to notify administrators
of the success status of scheduled tasks and encountered errors.
SQLServerAgent also has mail capabilities, but does not use the
SQL Mail service. Instead, it uses the SQLAgentMail component to
send notifications. These services are available only on the Standard
or Enterprise Edition of SQL Server.
On Windows NT Server and Windows 2000 Server, MSSQLServer,
SQLServerAgent, and MSDTC services can be started or stopped, as
Another Random Scribd Document
with Unrelated Content
GEDALIAH. xxxix.-xli., lii. 172

"Then arose Ishmael ben Nethaniah, and the ten men that were
with him, and smote with the sword and slew Gedaliah ben
Ahikam ben Shaphan, whom the king of Babylon had made
king over the land."—xli. 2

CHAPTER XIV

THE DESCENT INTO EGYPT. xlii., xliii. 187

"They came into the land of Egypt, for they obeyed not the voice
of Jehovah."—xliii. 7

CHAPTER XV

THE QUEEN OF HEAVEN. xliv. 197

"Since we left off burning incense and offering libations to the


Queen of Heaven, we have been in want of everything, and
have been consumed by the sword and the famine."—xliv. 18

BOOK II

PROPHECIES CONCERNING FOREIGN NATIONS

CHAPTER XVI

JEHOVAH AND THE NATIONS. xxv. 15-38 211

"Jehovah hath a controversy with the nations."—xxv. 31

CHAPTER XVII

EGYPT. xliii. 8-13, xliv. 30, xlvi. 220

"I will visit Amon of No, and Pharaoh, and Egypt, with their gods
and their kings; even Pharaoh, and all them that trust in
him."—xlvi. 25

CHAPTER XVIII
THE PHILISTINES. xlvii. 230

"O sword of Jehovah, how long will it be ere thou be quiet? put
up thyself into thy scabbard; rest, and be still."—xlvii. 6

CHAPTER XIX

MOAB. xlviii. 234

"Moab shall be destroyed from being a people, because he hath


magnified himself against Jehovah."—xlviii. 42
"Chemosh said to me, Go, take Nebo against Israel ... and I took
it ... and I took from it the vessels of Jehovah, and offered
them before Chemosh."—Moabite Stone.
"Yet will I bring again the captivity of Moab in the latter days."—
xlviii. 47

CHAPTER XX

AMMON. xlix. 1-6 242

"Hath Israel no sons? hath he no heir? why then doth Moloch


possess Gad, and his people dwell in the cities thereof?"—
xlix. 1

CHAPTER XXI

EDOM. xlix. 7-22 243

"Bozrah shall become an astonishment, a reproach, a waste, and


a curse."—xlix. 13

CHAPTER XXII

DAMASCUS. xlix. 23-27 248

"I will kindle a fire in the wall of Damascus, and it shall devour
the palaces of Benhadad."—xlix. 27

CHAPTER XXIII

KEDAR AND HAZOR. xlix. 28-33 251


"Concerning Kedar, and the kingdoms of Hazor which
Nebuchadnezzar king of Babylon smote."—xlix. 28

CHAPTER XXIV

ELAM. xlix. 34-39 255

"I will break the bow of Elam, the chief of their might."—xlix. 35

CHAPTER XXV

BABYLON. l., li. 258

"Babylon is taken, Bel is confounded, Merodach is broken in


pieces."—l. 2

BOOK III

JEREMIAH'S TEACHING CONCERNING ISRAEL AND JUDAH

CHAPTER XXVI

INTRODUCTORY 267

"I will be the God of all the families of Israel, and they shall be
My people."—xxxi. 1

CHAPTER XXVII

SOCIAL AND RELIGIOUS CORRUPTION 270

"Very bad figs, ... too bad to be eaten."—xxiv. 2, 8, xxix. 17

CHAPTER XXVIII

PERSISTENT APOSTASY 283

"They have forsaken the covenant of Jehovah their God, and


worshipped other gods, and served them."—xxii. 9
"Every one that walketh in the stubbornness of his heart."—xxiii.
17

CHAPTER XXIX

RUIN. xxii. 1-9, xxvi. 14 295

"The sword, the pestilence, and the famine."—xxi, 9 and passim.


"Terror on every side."—vi. 25, xx. 10, xlvi. 5, xlix. 29; also as
proper name, MAGOR-MISSABIB, xx. 3

CHAPTER XXX

RESTORATION—I. THE SYMBOL. xxxii. 308

"And I bought the field of Hanameel."—xxxii. 9

CHAPTER XXXI

RESTORATION—II. THE NEW ISRAEL. xxiii. 3-8, xxiv. 6, 7, xxx., xxxi.,


xxxiii. 319

"In those days shall Judah be saved, and Jerusalem shall dwell
safely: and this is the name whereby she shall be called,
Jehovah our Righteousness."—xxxiii. 16

CHAPTER XXXII

RESTORATION—III. REUNION. xxxi. 329

"I will sow the house of Israel and the house of Judah with the
seed of man, and with the seed of beast."—xxxi. 27

CHAPTER XXXIII

RESTORATION—IV. THE NEW COVENANT. xxxi. 31-38: cf. Hebrews


viii. 346

"I will make a new covenant with the house of Israel and the
house of Judah."—xxxi. 31
CHAPTER XXXIV

RESTORATION—V. REVIEW. xxx.-xxxiii. 357

EPILOGUE

CHAPTER XXXV

JEREMIAH AND CHRIST 367

"Jehovah thy God will raise up unto thee a prophet from amongst
thee, of thy brethren, like unto me; unto him shall ye
hearken."—Deut. xviii. 15
"Jesus ... asked His disciples, saying, Who do men say that the
Son of Man is? And they said, Some say John the Baptist;
some, Elijah: and others, Jeremiah, or one of the
prophets."—Matt. xvi. 13, 14
BOOK I
PERSONAL UTTERANCES AND NARRATIVES
CHAPTER I
INTRODUCTORY:[2] JEHOAHAZ
xxii. 10-12.

"Weep ye not for the dead, neither bemoan him: but weep sore for him that goeth
away: for he shall return no more."—Jer. xxii. 10.

As the prophecies of Jeremiah are not arranged in the order in which they were delivered,
there is no absolute chronological division between the first twenty chapters and those
which follow. For the most part, however, chapters xxi.-lii. fall in or after the fourth year
of Jehoiakim (b.c. 605). We will therefore briefly consider the situation at Jerusalem in
this crisis. The period immediately preceding b.c. 605 somewhat resembles the era of the
dissolution of the Roman Empire or of the Wars of the French Revolution. An old-
established international system was breaking in pieces, and men were quite uncertain
what form the new order would take. For centuries the futile assaults of the Pharaohs had
only served to illustrate the stability of the Assyrian supremacy in Western Asia. Then in
the last two decades of the seventh century b.c. the Assyrian Empire collapsed, like the
Roman Empire under Honorius and his successors. It was as if by some swift succession
of disasters modern France or Germany were to become suddenly and permanently
annihilated as a military power. For the moment, all the traditions and principles of
European statesmanship would lose their meaning, and the shrewdest diplomatist would
be entirely at fault. Men's reason would totter, their minds would lose their balance at the
stupendous spectacle of so unparalleled a catastrophe. The wildest hopes would alternate
with the extremity of fear; everything would seem possible to the conqueror.
Such was the situation in b.c. 605, to which our first great group of prophecies belongs.
Two oppressors of Israel—Assyria and Egypt—had been struck down in rapid succession.
When Nebuchadnezzar[3] was suddenly recalled to Babylon by the death of his father, the
Jews would readily imagine that the Divine judgment had fallen upon Chaldea and its
king. Sanguine prophets announced that Jehovah was about to deliver His people from all
foreign dominion, and establish the supremacy of the Kingdom of God. Court and people
would be equally possessed with patriotic hope and enthusiasm. Jehoiakim, it is true, was
a nominee of Pharaoh Necho; but his gratitude would be far too slight to override the
hopes and aspirations natural to a Prince of the House of David.
In Hezekiah's time, there had been an Egyptian and an Assyrian party at the court of
Judah; the recent supremacy of Egypt had probably increased the number of her
partisans. Assyria had disappeared, but her former adherents would retain their antipathy
to Egypt, and their personal feuds with Jews of the opposite faction; they were as tools
lying ready to any hand that cared to use them. When Babylon succeeded Assyria in the
overlordship of Asia, she doubtless inherited the allegiance of the anti-Egyptian party in
the various Syrian states. Jeremiah, like Isaiah, steadily opposed any dependence upon
Egypt; it was probably by his advice that Josiah undertook his ill-fated expedition against
Pharaoh Necho. The partisans of Egypt would be the prophet's enemies; and though
Jeremiah never became a mere dependent and agent of Nebuchadnezzar, yet the friends
of Babylon would be his friends, if only because her enemies were his enemies.
We are told in 2 Kings xxiii. 37 that Jehoiakim did evil in the sight of Jehovah according to
all that his father had done. Whatever other sins may be implied by this condemnation,
we certainly learn that the king favoured a corrupt form of the religion of Jehovah in
opposition to the purer teaching which Jeremiah inherited from Isaiah.
When we turn to Jeremiah himself, the date "the fourth year of Jehoiakim" reminds us
that by this time the prophet could look back upon a long and sad experience; he had
been called in the thirteenth year of Josiah, some twenty-four years before. With what
sometimes seems to our limited intelligence the strange irony of Providence, this lover of
peace and quietness was called to deliver a message of ruin and condemnation, a
message that could not fail to be extremely offensive to most of his hearers, and to make
him the object of bitter hostility.
Much of this Jeremiah must have anticipated, but there were some from whose position
and character the prophet expected acceptance, even of the most unpalatable teaching
of the Spirit of Jehovah. The personal vindictiveness with which priests and prophets
repaid his loyalty to the Divine mission and his zeal for truth came to him with a shock of
surprise and bewilderment, which was all the greater because his most determined
persecutors were his sacerdotal kinsmen and neighbours at Anathoth. "Let us destroy the
tree," they said, "with the fruit thereof, and let us cut him off from the land of the living,
that his name may be no more remembered."[4]
He was not only repudiated by his clan, but also forbidden by Jehovah to seek consolation
and sympathy in the closer ties of family life: "Thou shalt not take a wife, thou shalt have
no sons or daughters."[5] Like Paul, it was good for Jeremiah "by reason of the present
distress" to deny himself these blessings. He found some compensation in the fellowship
of kindred souls at Jerusalem. We can well believe that, in those early days, he was
acquainted with Zephaniah, and that they were associated with Hilkiah and Shaphan and
King Josiah in the publication of Deuteronomy and its recognition as the law of Israel.
Later on Shaphan's son Ahikam protected Jeremiah when his life was in imminent danger.
The twelve years that intervened between Josiah's Reformation and his defeat at Megiddo
were the happiest part of Jeremiah's ministry. It is not certain that any of the extant
prophecies belong to this period. With Josiah on the throne and Deuteronomy accepted
as the standard of the national life, the prophet felt absolved for a season from his
mission to pluck up and break down, and perhaps began to indulge in hopes that the
time had come to build and to plant. Yet it is difficult to believe that he had implicit
confidence in the permanence of the Reformation or the influence of Deuteronomy. The
silence of Isaiah and Jeremiah as to the ecclesiastical reforms of Hezekiah and Josiah
stands in glaring contrast to the great importance attached to them by the Books of Kings
and Chronicles. But, in any case, Jeremiah must have found life brighter and easier than
in the reigns that followed. Probably, in these happier days, he was encouraged by the
sympathy and devotion of disciples like Baruch and Ezekiel.
But Josiah's attempt to realise a Kingdom of God was short-lived; and, in a few months,
Jeremiah saw the whole fabric swept away. The king was defeated and slain; and his
religious policy was at once reversed either by a popular revolution or a court intrigue.
The people of the land made Josiah's son Shallum king, under the name of Jehoahaz.
This young prince of twenty-three only reigned three months, and was then deposed and
carried into captivity by Pharaoh Necho; yet it is recorded of him, that he did evil in the
sight of Jehovah, according to all that his fathers had done.[6] He—or, more probably, his
ministers, especially the queen-mother[7]—must have been in a hurry to undo Josiah's
work. Jeremiah utters no condemnation of Jehoahaz; he merely declares that the young
king will never return from his exile, and bids the people lament over his captivity as a
more grievous fate than the death of Josiah:—

"Weep not for the dead,


Neither lament over him:
But weep sore for him that goeth into captivity;
For he shall return no more,
Neither shall he behold his native land."[8]

Ezekiel adds admiration to sympathy: Jehoahaz was a young lion skilled to catch the prey,
he devoured men, the nations heard of him, he was taken in their pit, and they brought
him with hooks into the land of Egypt.[9] Jeremiah and Ezekiel could not but feel some
tenderness towards the son of Josiah; and probably they had faith in his personal
character, and believed that in time he would shake off the yoke of evil counsellors and
follow in his father's footsteps. But any such hopes were promptly disappointed by
Pharaoh Necho, and Jeremiah's spirit bowed beneath a new burden as he saw his country
completely subservient to the dreaded influence of Egypt.
Thus, at the time when we take up the narrative, the government was in the hands of the
party hostile to Jeremiah, and the king, Jehoiakim, seems to have been his personal
enemy. Jeremiah himself was somewhere between forty and fifty years old, a solitary
man without wife or child. His awful mission as the herald of ruin clouded his spirit with
inevitable gloom. Men resented the stern sadness of his words and looks, and turned
from him with aversion and dislike. His unpopularity had made him somewhat harsh; for
intolerance is twice curst, in that it inoculates its victims with the virus of its own
bitterness. His hopes and illusions lay behind him; he could only watch with melancholy
pity the eager excitement of these stirring times. If he came across some group busily
discussing the rout of the Egyptians at Carchemish, or the report that Nebuchadnezzar
was posting in hot haste to Babylon, and wondering as to all that this might mean for
Judah, his countrymen would turn to look with contemptuous curiosity at the bitter,
disappointed man who had had his chance and failed, and now grudged them their
prospect of renewed happiness and prosperity. Nevertheless Jeremiah's greatest work still
lay before him. Jerusalem was past saving; but more was at stake than the existence of
Judah and its capital. But for Jeremiah the religion of Jehovah might have perished with
His Chosen People. It was his mission to save Revelation from the wreck of Israel.
Humanly speaking, the religious future of the world depended upon this stern solitary
prophet.
CHAPTER II
A TRIAL FOR HERESY
xxvi.: cf. vii.-x.

"When Jeremiah had made an end of speaking all that Jehovah had commanded him
to speak unto all the people, the priests and the prophets and all the people laid hold
on him, saying, Thou shalt surely die."—Jer. xxvi. 8.

The date of this incident is given, somewhat vaguely, as the beginning of the reign of
Jehoiakim. It was, therefore, earlier than b.c. 605, the point reached in the previous
chapter. Jeremiah could offer no political resistance to Jehoiakim and his Egyptian
suzerain; yet it was impossible for him to allow Josiah's policy to be reversed without a
protest. Moreover, something, perhaps much, might yet be saved for Jehovah. The king,
with his court and prophets and priests, was not everything. Jeremiah was only
concerned with sanctuaries, ritual, and priesthoods as means to an end. For him the most
important result of the work he had shared with Josiah was a pure and holy life for the
nation and individuals. Renan—in some passages, for he is not always consistent—is
inclined to minimise the significance of the change from Josiah to Jehoiakim; in fact, he
writes very much as a cavalier might have done of the change from Cromwell to Charles
II. Both the Jewish kings worshipped Jehovah, each in his own fashion: Josiah was
inclined to a narrow puritan severity of a life; Jehoiakim was a liberal, practical man of the
world. Probably this is a fair modern equivalent of the current estimate of the kings and
their policy, especially on the part of Jehoiakim's friends; but then, as unhappily still in
some quarters, "narrow puritan severity" was a convenient designation for a decent and
honourable life, for a scrupulous and self-denying care for the welfare of others. Jeremiah
dreaded a relapse into the old half-heathen ideas that Jehovah would be pleased with
homage and service that satisfied Baal, Moloch, and Chemosh. Such a relapse would
lower the ethical standard, and corrupt or even destroy any beginnings of spiritual life.
Our English Restoration is an object-lesson as to the immoral effects of political and
ecclesiastical reaction; if such things were done in sober England, what must have been
possible to hot Eastern blood! In protesting against the attitude of Jehoiakim, Jeremiah
would also seek to save the people from the evil effects of the king's policy. He knew
from his own experience that a subject might trust and serve God with his whole heart,
even when the king was false to Jehovah. What was possible for him was possible for
others. He understood his countrymen too well to expect that the nation would continue
to advance in paths of righteousness which its leaders and teachers had forsaken; but,
scattered here and there through the mass of the people, was Isaiah's remnant, the seed
of the New Israel, men and women to whom the Revelation of Jehovah had been the
beginning of a higher life. He would not leave them without a word of counsel and
encouragement.
At the command of Jehovah, Jeremiah appeared before the concourse of Jews,
assembled at the Temple for some great fast or festival. No feast is expressly mentioned,
but he is charged to address "all the cities of Judah"[10]; all the outlying population would
only meet at the Temple on some specially holy day. Such an occasion would naturally be
chosen by Jeremiah for his deliverance, just as Christ availed Himself of the opportunities
offered by the Passover and the Feast of Tabernacles, just as modern philanthropists seek
to find a place for their favourite topics on the platform of May Meetings.
The prophet was to stand in the court of the Temple and repeat once more to the Jews
his message of warning and judgment, "all that I have charged thee to speak unto them,
thou shalt not keep back a single word." The substance of this address is found in the
various prophecies which expose the sin and predict the ruin of Judah. They have been
dealt with in the former volume[11] on Jeremiah in this series, and are also referred to in
Book III.
According to the universal principle of Hebrew prophecy, the predictions of ruin were
conditional; they were still coupled with the offer of pardon to repentance, and Jehovah
did not forbid his prophet to cherish a lingering hope that "perchance they may hearken
and turn every one from his evil way, so that I may repent Me of the evil I purpose to
inflict upon them because of the evil of their doings." Probably the phrase "every one
from his evil way" is primarily collective rather than individual, and is intended to describe
a national reformation, which would embrace all the individual citizens; but the actual
words suggest another truth, which must also have been in Jeremiah's mind. The nation
is, after all, an aggregate of men and women; there can be no national reformation,
except through the repentance and amendment of individuals.
Jeremiah's audience, it must be observed, consisted of worshippers on the way to the
Temple, and would correspond to an ordinary congregation of church-goers, rather than
to the casual crowd gathered round a street preacher, or to the throngs of miners and
labourers who listened to Whitfield and Wesley. As an acknowledged prophet, he was well
within his rights in expecting a hearing from the attendants at the feast, and men would
be curious to see and hear one who had been the dominant influence in Judah during the
reign of Josiah. Moreover, in the absence of evening newspapers and shop-windows, a
prophet was too exciting a distraction to be lightly neglected. From Jehovah's charge to
speak all that He had commanded him to speak and not to keep back a word, we may
assume that Jeremiah's discourse was long: it was also avowedly an old sermon[12]; most
of his audience had heard it before, all of them were quite familiar with its main topics.
They listened in the various moods of a modern congregation "sitting under" a
distinguished preacher. Jeremiah's friends and disciples welcomed the ideas and phrases
that had become part of their spiritual life. Many enjoyed the speaker's earnestness and
eloquence, without troubling themselves about the ideas at all. There was nothing
specially startling about the well-known threats and warnings; they had become

"A tale of little meaning tho' the words were strong."

Men hardened their hearts against inspired prophets as easily as they do against the
most pathetic appeals of modern evangelists. Mingled with the crowd were Jeremiah's
professional rivals, who detested both him and his teaching—priests who regarded him as
a traitor to his own caste, prophets who envied his superior gifts and his force of
passionate feeling. To these almost every word he uttered was offensive, but for a while
there was nothing that roused them to very vehement anger. He was allowed to finish
what he had to say, "to make an end of speaking all that Jehovah had commanded him."
But in this peroration he had insisted on a subject that stung the indifferent into
resentment and roused the priests and prophets to fury.
"Go ye now unto My place which was in Shiloh, where I caused My name to dwell at the
first, and see what I did to it for the wickedness of My people Israel. And now, because
ye have done all these works, saith Jehovah, and I spake unto you, rising up early and
speaking, but ye heard not; and I called you, but ye answered not: therefore will I do
unto the house, that is called by My name, wherein ye trust, and unto the place which I
gave to you and to your fathers, as I have done to Shiloh."[13]
The Ephraimite sanctuary of Shiloh, long the home of the Ark and its priesthood, had
been overthrown in some national catastrophe. Apparently when it was destroyed it was
no mere tent, but a substantial building of stone, and its ruins remained as a permanent
monument of the fugitive glory of even the most sacred shrine.
The very presence of his audience in the place where they were met showed their
reverence for the Temple: the priests were naturally devotees of their own shrine; of the
prophets Jeremiah himself had said, "The prophets prophesy falsely, and the priests rule
in accordance with their teaching."[14] Can we wonder that "the priests and the prophets
and all the people laid hold on him, saying, Thou shalt surely die"? For the moment there
was an appearance of religious unity in Jerusalem; the priests, the prophets, and the
pious laity on one side, and only the solitary heretic on the other. It was, though on a
small scale, as if the obnoxious teaching of some nineteenth-century prophet of God had
given an unexpected stimulus to the movement for Christian reunion; as if cardinals and
bishops, chairmen of unions, presidents of conferences, moderators of assemblies, with
great preachers and distinguished laymen, united to hold monster meetings and
denounce the Divine message as heresy and blasphemy. In like manner Pharisees,
Sadducees, and Herodians found a basis of common action in their hatred of Christ, and
Pilate and Herod were reconciled by His cross.
Meanwhile the crowd was increasing: new worshippers were arriving, and others as they
left the Temple were attracted to the scene of the disturbance. Doubtless too the mob,
always at the service of persecutors, hurried up in hope of finding opportunities for
mischief and violence. Some six and a half centuries later, history repeated itself on the
same spot, when the Asiatic Jews saw Paul in the Temple and "laid hands on him, crying
out, Men of Israel, help: This is the man, that teacheth all men everywhere against the
people and the law and this place, ... and all the city was moved, and the people ran
together and laid hold on Paul."[15]
Our narrative, as it stands, is apparently incomplete: we find Jeremiah before the tribunal
of the princes, but we are not told how he came there; whether the civil authorities
intervened to protect him, as Claudius Lysias came down with his soldiers and centurions
and rescued Paul, or whether Jeremiah's enemies observed legal forms, as Annas and
Caiaphas did when they arrested Christ. But, in any case, "the princes of Judah, when
they heard these things, came up from the palace into the Temple, and took their seats
as judges at the entry of the new gate of the Temple." The "princes of Judah" play a
conspicuous part in the last period of the Jewish monarchy: we have little definite
information about them, and are left to conjecture that they were an aristocratic oligarchy
or an official clique, or both; but it is clear that they were a dominant force in the state,
with recognised constitutional status, and that they often controlled the king himself. We
are also ignorant as to the "new gate"; it may possibly be the upper gate built by
Jotham[16] about a hundred and fifty years earlier.
Before these judges, Jeremiah's ecclesiastical accusers brought a formal charge; they
said, almost in the very words which the high priest and the Sanhedrin used of Christ,
"This man is worthy of death, for he hath prophesied against this city, as ye have heard
with your ears"—i.e. when he said, "This house shall be like Shiloh, and this city shall be
desolate without inhabitant." Such accusations have been always on the lips of those who
have denounced Christ and His disciples as heretics. One charge against Himself was that
He said, "I will destroy this Temple that is made with hands, and in three days I will build
another that is made without hands."[17] Stephen was accused of speaking incessantly
against the Temple and the Law, and teaching that Jesus of Nazareth would destroy the
Temple and change the customs handed down from Moses. When he asserted that "the
Most High dwelleth not in temples made with hands," the impatience of his audience
compelled him to bring his defence to an abrupt conclusion.[18] Of Paul we have already
spoken.
How was it that these priests and prophets thought that their princes might be induced to
condemn Jeremiah to death for predicting the destruction of the Temple? A prophet
would not run much risk nowadays by announcing that St. Paul's should be made like
Stonehenge, or St. Peter's like the Parthenon. Expositors of Daniel and the Apocalypse
habitually fix the end of the world a few years in advance of the date at which they write,
and yet they do not incur any appreciable unpopularity. It is true that Jeremiah's accusers
were a little afraid that his predictions might be fulfilled, and the most bitter persecutors
are those who have a lurking dread that their victims are right, while they themselves are
wrong. But such fears could not very well be evidence or argument against Jeremiah
before any court of law.
In order to realise the situation we must consider the place which the Temple held in the
hopes and affections of the Jews. They had always been proud of their royal sanctuary at
Jerusalem, but within the last hundred and fifty years it had acquired a unique
importance for the religion of Israel. First Hezekiah, and then Josiah, had taken away the
other high places and altars at which Jehovah was worshipped, and had said to Judah
and Jerusalem, "Ye shall worship before this altar."[19] Doubtless the kings were following
the advice of Isaiah and Jeremiah. These prophets were anxious to abolish the abuses of
the local sanctuaries, which were a continual incentive to an extravagant and corrupt
ritual. Yet they did not intend to assign any supreme importance to a priestly caste or a
consecrated building. Certainly for them the hope of Israel and the assurance of its
salvation did not consist in cedar and hewn stones, in silver and gold. And yet the unique
position given to the Temple inevitably became the starting-point for fresh superstition.
Once Jehovah could be worshipped not only at Jerusalem, but at Beersheba and Bethel
and many other places where He had chosen to set His name. Even then, it was felt that
the Divine Presence must afford some protection for His dwelling-places. But now that
Jehovah dwelt nowhere else but at Jerusalem, and only accepted the worship of His
people at this single shrine, how could any one doubt that He would protect His Temple
and His Holy City against all enemies, even the most formidable? Had He not done so
already?
When Hezekiah abolished the high places, did not Jehovah set the seal of approval upon
his policy by destroying the army of Sennacherib? Was not this great deliverance wrought
to guard the Temple against desecration and destruction, and would not Jehovah work
out a like salvation in any future time of danger? The destruction of Sennacherib was
essential to the religious future of Israel and of mankind; but it had a very mingled
influence upon the generations immediately following. They were like a man who has
won a great prize in a lottery, or who has, quite unexpectedly, come into an immense
inheritance. They ignored the unwelcome thought that the Divine protection depended on
spiritual and moral conditions, and they clung to the superstitious faith that at any
moment, even in the last extremity of danger and at the eleventh hour, Jehovah might,
nay, even must, intervene. The priests and the inhabitants of Jerusalem could look on
with comparative composure while the country was ravaged, and the outlying towns were
taken and pillaged; Jerusalem itself might seem on the verge of falling into the hands of
the enemy, but they still trusted in their Palladium. Jerusalem could not perish, because it
contained the one sanctuary of Jehovah; they sought to silence their own fears and to
drown the warning voice of the prophet by vociferating their watchword: "The Temple of
Jehovah! the Temple of Jehovah! The Temple of Jehovah is in our midst!"[20]
In prosperous times a nation may forget its Palladium, and may tolerate doubts as to its
efficacy; but the strength of the Jews was broken, their resources were exhausted, and
they were clinging in an agony of conflicting hopes and fears to their faith in the
inviolability of the Temple. To destroy their confidence was like snatching away a plank
from a drowning man. When Jeremiah made the attempt, they struck back with the fierce
energy of despair. It does not seem that at this time the city was in any immediate
danger; the incident rather falls in the period of quiet submission to Pharaoh Necho that
preceded the battle of Carchemish. But the disaster of Megiddo was fresh in men's
memories, and in the unsettled state of Eastern Asia no one knew how soon some other
invader might advance against the city. On the other hand, in the quiet interval, hopes
began to revive, and men were incensed when the prophet made haste to nip these
hopes in the bud, all the more so because their excited anticipations of future glory had
so little solid basis. Jeremiah's appeal to the ill-omened precedent of Shiloh naturally
roused the sanguine and despondent alike into frenzy.
Jeremiah's defence was simple and direct: "Jehovah sent me to prophesy all that ye have
heard against this house and against this city. Now therefore amend your ways and your
doings, and hearken unto the voice of Jehovah your God, that He may repent Him of the
evil that He hath spoken against you. As for me, behold, I am in your hands: do unto me
as it seems good and right unto you. Only know assuredly that, if ye put me to death, ye
will bring the guilt of innocent blood upon yourselves, and upon this city and its
inhabitants: for of a truth Jehovah sent me unto you to speak all these words in your
ears." There is one curious feature in this defence. Jeremiah contemplates the possibility
of two distinct acts of wickedness on the part of his persecutors: they may turn a deaf
ear to his appeal that they should repent and reform, and their obstinacy will incur all the
chastisements which Jeremiah had threatened; they may also put him to death and incur
additional guilt. Scoffers might reply that his previous threats were so awful and
comprehensive that they left no room for any addition to the punishment of the
impenitent. Sinners sometimes find a grim comfort in the depth of their wickedness; their
case is so bad that it cannot be made worse, they may now indulge their evil propensities
with a kind of impunity. But Jeremiah's prophetic insight made him anxious to save his
countrymen from further sin, even in their impenitence; the Divine discrimination is not
taxed beyond its capabilities even by the extremity of human wickedness.
But to return to the main feature in Jeremiah's defence. His accusers' contention was that
his teaching was so utterly blasphemous, so entirely opposed to every tradition and
principle of true religion—or, as we should say, so much at variance with all orthodoxy—
that it could not be a word of Jehovah. Jeremiah does not attempt to discuss the relation
of his teaching to the possible limits of Jewish orthodoxy. He bases his defence on the
bare assertion of his prophetic mission—Jehovah had sent him. He assumes that there is
no room for evidence or discussion; it is a question of the relative authority of Jeremiah
and his accusers, whether he or they had the better right to speak for God. The
immediate result seemed to justify him in this attitude. He was no obscure novice,
seeking for the first time to establish his right to speak in the Divine name. The princes
and people had been accustomed for twenty years to listen to him, as to the most fully
acknowledged mouthpiece of Heaven; they could not shake off their accustomed feeling
of deference, and once more succumbed to the spell of his fervid and commanding
personality. "Then said the princes and all the people unto the priests and the prophets,
This man is not worthy of death; for he hath spoken to us in the name of Jehovah our
God." For the moment the people were won over and the princes convinced; but priests
and prophets were not so easily influenced by inspired utterances; some of these
probably thought that they had an inspiration of their own, and their professional
experience made them callous.
At this point again the sequence of events is not clear; possibly the account was compiled
from the imperfect recollections of more than one of the spectators. The pronouncement
of the princes and the people seems, at first sight, a formal acquittal that should have
ended the trial, and left no room for the subsequent intervention of "certain of the
elders," otherwise the trial seems to have come to no definite conclusion, and the
incident simply terminated in the personal protection given to Jeremiah by Ahikam ben
Shaphan. Possibly, however, the tribunal of the princes was not governed by any strict
rules of procedure; and the force of the argument used by the elders does not depend on
the exact stage of the trial at which it was introduced.
Either Jeremiah was not entirely successful in his attempt to get the matter disposed of
on the sole ground of his own prophetic authority, or else the elders were anxious to
secure weight and finality for the acquittal, by bringing forward arguments in its support.
The elders were an ancient Israelite institution, and probably still represented the
patriarchal side of the national life; nothing is said as to their relation to the princes, and
this might not be very clearly defined. The elders appealed, by way of precedent, to an
otherwise unrecorded incident of the reign of Hezekiah. Micah the Morasthite had uttered
similar threats against Jerusalem and the Temple: "Zion shall be ploughed as a field, and
Jerusalem shall become heaps, and the mountain of the house as the high places of the
forest."[21] But Hezekiah and his people, instead of slaying Micah, had repented, and the
city had been spared. They evidently wished that the precedent could be wholly followed
in the present instance; but, at any rate, it was clear that one of the most honoured and
successful of the kings of Judah had accepted a threat against the Temple as a message
from Jehovah. Therefore the mere fact that Jeremiah had uttered such a threat was
certainly not primâ facie evidence that he was a false prophet. We are not told how this
argument was received, but the writer of the chapter, possibly Baruch, does not attribute
Jeremiah's escape either to his acquittal by the princes or to the reasoning of the elders.
The people apparently changed sides once more, like the common people in the New
Testament, who heard Christ gladly and with equal enthusiasm clamoured for His
crucifixion. At the end of the chapter we find them eager to have the prophet delivered
into their hands that they may put him to death. Apparently the prophets and priests,
having brought matters into this satisfactory position, had retired from the scene of
action; the heretic was to be delivered over to the secular arm. The princes, like Pilate,
seemed inclined to yield to popular pressure; but Ahikam, a son of the Shaphan who had
to do with the finding of Deuteronomy, stood by Jeremiah, as John of Gaunt stood by
Wyclif, and the Protestant Princes by Luther, and the magistrates of Geneva by Calvin;
and Jeremiah could say with the Psalmist:—

"I have heard the defaming of many,


Terror on every side:
While they took counsel together against me,
They devised to take away my life.
But I trusted in Thee, O Jehovah:
I said, Thou art my God.
My times are in Thy hand:
Deliver me from the hand of mine enemies, and from them that
persecute me.

Let the lying lips be dumb,


Which speak against the righteous insolently,
With pride and contempt.
Oh, how great is Thy goodness, which Thou hast laid up for them that
fear Thee,
Which Thou hast wrought for them that put their trust in Thee, before
the sons of men."[22]
We have here an early and rudimentary example of religious toleration, of the willingness,
however reluctant, to hear as a possible Divine message unpalatable teaching, at
variance with current theology; we see too the fountain-head of that freedom which since
has "broadened down from precedent to precedent."
But unfortunately no precedent can bind succeeding generations, and both Judaism and
Christianity have sinned grievously against the lesson of this chapter. Jehoiakim himself
soon broke through the feeble restraint of this new-born tolerance. The writer adds an
incident that must have happened somewhat later,[23] to show how real was Jeremiah's
danger, and how transient was the liberal mood of the authorities. A certain Uriah ben
Shemaiah of Kirjath Jearim had the courage to follow in Jeremiah's footsteps and speak
against the city "according to all that Jeremiah had said." With the usual meanness of
persecutors, Jehoiakim and his captains and princes vented upon this obscure prophet
the ill-will which they had not dared to indulge in the case of Jeremiah, with his
commanding personality and influential friends. Uriah fled into Egypt, but was brought
back and slain, and his body cast out unburied into the common cemetery. We can
understand Jeremiah's fierce and bitter indignation against the city where such things
were possible.
This chapter is so full of suggestive teaching that we can only touch upon two or three of
its more obvious lessons. The dogma which shaped the charge against Jeremiah and
caused the martyrdom of Uriah was the inviolability of the Temple and the Holy City. This
dogma was a perversion of the teaching of Isaiah, and especially of Jeremiah himself,[24]
which assigned a unique position to the Temple in the religion of Israel. The carnal man
shows a fatal ingenuity in sucking poison out of the most wholesome truth. He is always
eager to discover that something external, material, physical, concrete—some building,
organisation, ceremony, or form of words—is a fundamental basis of the faith and
essential to salvation. If Jeremiah had died with Josiah, the "priests and prophets" would
doubtless have quoted his authority against Uriah. The teaching of Christ and His
apostles, of Luther and Calvin and their fellow-reformers, has often been twisted and
forged into weapons to be used against their true followers. We are often tempted in the
interest of our favourite views to lay undue stress on secondary and accidental
statements of great teachers. We fail to keep the due proportion of truth which they
themselves observed, and in applying their precepts to new problems we sacrifice the
kernel and save the husk. The warning of Jeremiah's persecutors might often "give us
pause." We need not be surprised at finding priests and prophets eager and interested
champions of a perversion of revealed truth. Ecclesiastical office does not necessarily
confer any inspiration from above. The hereditary priest follows the traditions of his caste,
and even the prophet may become the mouthpiece of the passions and prejudices of
those who accept and applaud him. When men will not endure sound doctrine, they heap
to themselves teachers after their own lusts; having itching ears, they turn away their
ears from the truth and turn unto fables.[25] Jeremiah's experience shows that even an
apparent consensus of clerical opinion is not always to be trusted. The history of councils
and synods is stained by many foul and shameful blots; it was the Œcumenical Council at
Constance that burnt Huss, and most Churches have found themselves, at some time or
other, engaged in building the tombs of the prophets whom their own officials had stoned
in days gone by. We forget that Athanasius contra mundum implies also Athanasius
contra ecclesiam.
CHAPTER III
THE ROLL
xxxvi.

"Take thee a roll of a book, and write therein all the words that I have spoken unto
thee."—Jer. xxxvi. 2.

The incidents which form so large a proportion of the contents of our book do not make
up a connected narrative; they are merely a series of detached pictures: we can only
conjecture the doings and experiences of Jeremiah during the intervals. Chapter xxvi.
leaves him still exposed to the persistent hostility of the priests and prophets, who had
apparently succeeded in once more directing popular feeling against their antagonist. At
the same time, though the princes were not ill-disposed towards him, they were not
inclined to resist the strong pressure brought to bear upon them. Probably the attitude of
the populace varied from time to time, according to the presence among them of the
friends or enemies of the prophet; and, in the same way, we cannot think of "the princes"
as a united body, governed by a single impulse. The action of this group of notables
might be determined by the accidental preponderance of one or other of two opposing
parties. Jeremiah's only real assurance of safety lay in the personal protection extended
to him by Ahikam ben Shaphan. Doubtless other princes associated themselves with
Ahikam in his friendly action on behalf of the prophet.
Under these circumstances, Jeremiah would find it necessary to restrict his activity. Utter
indifference to danger was one of the most ordinary characteristics of Hebrew prophets,
and Jeremiah was certainly not wanting in the desperate courage which may be found in
any Mohammedan dervish. At the same time he was far too practical, too free from
morbid self-consciousness, to court martyrdom for its own sake. If he had presented
himself again in the Temple when it was crowded with worshippers, his life might have
been taken in a popular tumult, while his mission was still only half accomplished.
Possibly his priestly enemies had found means to exclude him from the sacred precincts.
Man's extremity was God's opportunity; this temporary and partial silencing of Jeremiah
led to a new departure, which made the influence of his teaching more extensive and
permanent. He was commanded to commit his prophecies to writing. The restriction of
his active ministry was to bear rich fruit, like Paul's imprisonment, and Athanasius' exile,
and Luther's sojourn in the Wartburg. A short time since there was great danger that
Jeremiah and the Divine message entrusted to him would perish together. He did not
know how soon he might become once more the mark of popular fury, nor whether
Ahikam would still be able to protect him. The roll of the book could speak even if he
were put to death.
But Jeremiah was not thinking chiefly about what would become of his teaching if he
himself perished. He had an immediate and particular end in view. His tenacious
persistence was not to be baffled by the prospect of mob violence, or by exclusion from
the most favourable vantage-ground. Renan is fond of comparing the prophets to modern
journalists; and this incident is an early and striking instance of the substitution of pen,
ink, and paper for the orator's tribune. Perhaps the closest modern parallel is that of the
speaker who is howled down at a public meeting and hands his manuscript to the
reporters.
In the record of the Divine command to Jeremiah, there is no express statement as to
what was to be done with the roll; but as the object of writing it was that "perchance the
house of Judah might hear and repent," it is evident that from the first it was intended to
be read to the people.

There is considerable difference of opinion[26] as to the contents of the roll. They are
described as: "All that I have spoken unto thee concerning[27] Jerusalem[28] and Judah,
and all the nations, since I (first) spake unto thee, from the time of Josiah until now." At
first sight this would seem to include all previous utterances, and therefore all the extant
prophecies of a date earlier than b.c. 605, i.e. those contained in chapters i.-xii. and some
portions of xiv.-xx. (we cannot determine which with any exactness), and probably most
of those dated in the fourth year of Jehoiakim, i.e. xxv. and parts of xlv.-xlix. Cheyne,[29]
however, holds that the roll simply contained the striking and comprehensive prophecy in
chapter xxv. The whole series of chapters might very well be described as dealing with
Jerusalem, Judah, and the nations; but at the same time xxv. might be considered
equivalent, by way of summary, to all that had been spoken on these subjects. From
various considerations which will appear as we proceed with the narrative, it seems
probable that the larger estimate is the more correct, i.e. that the roll contained a large
fraction of our Book of Jeremiah, and not merely one or two chapters. We need not,
however, suppose that every previous utterance of the prophet, even though still extant,
must have been included in the roll; the "all" would of course be understood to be
conditioned by relevancy; and the narratives of various incidents are obviously not part of
what Jehovah had spoken.
Jeremiah dictated his prophecies, as St. Paul did his epistles, to an amanuensis; he called
his disciple Baruch[30] ben Neriah, and dictated to him "all that Jehovah had spoken,
upon a book, in the form of a roll."
It seems clear that, as in xxvi., the narrative does not exactly follow the order of events,
[31] and that verse 9, which records the proclamation of a fast in the ninth month of
Jehoiakim's fifth year, should be read before verse 5, which begins the account of the
circumstances leading up to the actual reading of the roll. We are not told in what month
of Jehoiakim's fourth year Jeremiah received this command to write his prophecies in a
roll, but as they were not read till the ninth month of the fifth year, there must have been
an interval of at least ten months or a year between the Divine command and the reading
by Baruch. We can scarcely suppose that all or nearly all this delay was caused by
Jeremiah and Baruch's waiting for a suitable occasion. The long interval suggests that the
dictation took some time, and that therefore the roll was somewhat voluminous in its
contents, and that it was carefully compiled, not without a certain amount of revision.
When the manuscript was ready, its authors had to determine the right time at which to
read it; they found their desired opportunity in the fast proclaimed in the ninth month.
This was evidently an extraordinary fast, appointed in view of some pressing danger; and,
in the year following the battle of Carchemish, this would naturally be the advance of
Nebuchadnezzar. As our incident took place in the depth of winter, the months must be
reckoned according to the Babylonian year, which began in April; and the ninth month,
Kisleu, would roughly correspond to our December. The dreaded invasion would be
looked for early in the following spring, "at the time when kings go out to battle."[32]
Jeremiah does not seem to have absolutely determined from the first that the reading of
the roll by Baruch was to be a substitute for his own presence. He had probably hoped
that some change for the better in the situation might justify his appearance before a
great gathering in the Temple. But when the time came he was "hindered"[33]—we are
not told how—and could not go into the Temple. He may have been restrained by his own
prudence, or dissuaded by his friends, like Paul when he would have faced the mob in the
theatre at Ephesus; the hindrance may have been some ban under which he had been
placed by the priesthood, or it may have been some unexpected illness, or legal
uncleanness, or some other passing accident, such as Providence often uses to protect its
soldiers till their warfare is accomplished.
Accordingly it was Baruch who went up to the Temple. Though he is said to have read the
book "in the ears of all the people," he does not seem to have challenged universal
attention as openly as Jeremiah had done; he did not stand forth in the court of the
Temple,[34] but betook himself to the "chamber" of the scribe,[35] or secretary of state,
Gemariah ben Shaphan, the brother of Jeremiah's protector Ahikam. This chamber would
be one of the cells built round the upper court, from which the "new gate"[36] led into an
inner court of the Temple. Thus Baruch placed himself formally under the protection of
the owner of the apartment, and any violence offered to him would have been resented
and avenged by this powerful noble with his kinsmen and allies. Jeremiah's disciple and
representative took his seat at the door of the chamber, and, in full view of the crowds
who passed and repassed through the new gate, opened his roll and began to read aloud
from its contents. His reading was yet another repetition of the exhortations, warnings,
and threats which Jeremiah had rehearsed on the feast day when he spake to the people
"all that Jehovah had commanded him"; and still both Jehovah and His prophet promised
deliverance as the reward of repentance. Evidently the head and front of the nation's
offence had been no open desertion of Jehovah for idols, else His servants would not
have selected for their audience His enthusiastic worshippers as they thronged to His
Temple. The fast itself might have seemed a token of penitence, but it was not accepted
by Jeremiah, or put forward by the people, as a reason why the prophecies of ruin should
not be fulfilled. No one offers the very natural plea: "In this fast we are humbling
ourselves under the mighty hand of God, we are confessing our sins, and consecrating
ourselves afresh to service of Jehovah. What more does He expect of us? Why does He
still withhold His mercy and forgiveness? Wherefore have we fasted, and Thou seest not?
Wherefore have we afflicted our soul, and Thou takest no knowledge?" Such a plea would
probably have received an answer similar to that given by one of Jeremiah's successors:
"Behold, in the day of your fast ye find your own pleasure, and oppress all your labourers.
Behold, ye fast for strife and contention, and to smite with the fist of wickedness: ye fast
not this day so as to make your voice to be heard on high. Is such the fast that I have
chosen? the day for a man to afflict his soul? Is it to bow down his head as a rush, and to
spread sackcloth and ashes under him? wilt thou call this a fast, and a day acceptable to
Jehovah?"
"Is not this the fast that I have chosen? to loose the bonds of wickedness, to undo the
bands of the yoke, and to let the oppressed go free, and that ye break every yoke? Is it
not to deal thy bread to the hungry, and that thou bring the poor that are cast out to thy
house? when thou seest the naked, that thou cover him; and that thou hide not thyself
from thine own flesh? Then shall thy light break forth as the morning, and thy healing
shall spring forth speedily: and thy righteousness shall go before thee; the glory of
Jehovah shall be thy rearward."[37]
Jeremiah's opponents did not grudge Jehovah His burnt-offerings and calves of a year
old; He was welcome to thousands of rams, and ten thousands of rivers of oil. They were
even willing to give their firstborn for their transgression, the fruit of their body for the sin
of their soul; but they were not prepared "to do justly, and to love mercy, and to walk
humbly with their God."[38]
We are not told how Jeremiah and the priests and prophets formulated the points at issue
between them, which were so thoroughly and universally understood that the record
takes them for granted. Possibly Jeremiah contended for the recognition of Deuteronomy,
with its lofty ideals of pure religion and a humanitarian order of society. But, in any case,
these incidents were an early phase of the age-long struggle of the prophets of God
against the popular attempt to make ritual and sensuous emotion into excuses for
ignoring morality, and to offer the cheap sacrifice of a few unforbidden pleasures, rather
than surrender the greed of grain, the lust of power, and the sweetness of revenge.
When the multitudes caught the sound of Baruch's voice and saw him sitting in the
doorway of Gemariah's chamber, they knew exactly what they would hear. To them he
was almost as antagonistic as a Protestant evangelist would be to the worshippers at
some great Romanist feast; or perhaps we might find a closer parallel in a Low Church
bishop addressing a ritualistic audience. For the hearts of these hearers were not steeled
by the consciousness of any formal schism. Baruch and the great prophet whom he
represented did not stand outside the recognised limits of Divine inspiration. While the
priests and prophets and their adherents repudiated his teaching as heretical, they were
still haunted by the fear that, at any rate, his threats might have some Divine authority.
Apart from all theology, the prophet of evil always finds an ally in the nervous fears and
guilty conscience of his hearer.
The feelings of the people would be similar to those with which they had heard the same
threats against Judah, the city and the Temple, from Jeremiah himself. But the
excitement aroused by the defeat of Pharaoh and the hasty return of Nebuchadnezzar to
Babylon had died away. The imminence of a new invasion made it evident that this had
not been the Divine deliverance of Judah. The people were cowed by what must have
seemed to many the approaching fulfilments of former threatenings; the ritual of a fast
was in itself depressing; so that they had little spirit to resent the message of doom.
Perhaps too there was less to resent: the prophecies were the same, but Baruch may
have been less unpopular than Jeremiah, and his reading would be tame and ineffective
compared to the fiery eloquence of his master. Moreover the powerful protection which
shielded him was indicated not only by the place he occupied, but also by the presence of
Gemariah's son, Micaiah.
The reading passed off without any hostile demonstration on the part of the people, and
Micaiah went in search of his father to describe to him the scene he had just witnessed.
He found him in the palace, in the chamber of the secretary of state, Elishama, attending
a council of the princes. There were present, amongst others, Elnathan ben Achbor, who
brought Uriah back from Egypt, Delaiah ben Shemaiah, and Zedekiah ben Hananiah.
Micaiah told them what he had heard. They at once sent for Baruch and the roll. Their
messenger, Jehudi ben Nethaniah, seems to have been a kind of court-usher. His name
signifies "the Jew," and as his great-grandfather was Cushi, "the Ethiopian," it has been
suggested that he came of a family of Ethiopian descent, which had only attained in his
generation to Jewish citizenship.[39]
When Baruch arrived, the princes greeted him with the courtesy and even deference due
to the favourite disciple of a distinguished prophet. They invited him to sit down and read
them the roll. Baruch obeyed; the method of reading suited the enclosed room and the
quiet, interested audience of responsible men, better than the swaying crowd gathered
round the door of Gemariah's chamber. Baruch now had before him ministers of state
who knew from their official information and experience how extremely probable it was
that the words to which they were listening would find a speedy and complete fulfilment.
Baruch must almost have seemed to them like a doomster who announces to a
condemned criminal the ghastly details of his coming execution. They exchanged looks of
dismay and horror, and when the reading was over, they said to one another,[40] "We
must tell the king of all these words." First, however, they inquired concerning the exact
circumstances under which the roll had been written, that they might know how far
responsibility in this matter was to be divided between the prophet and his disciple, and
also whether all the contents rested upon the full authority of Jeremiah. Baruch assured
them that it was simply a case of dictation: Jeremiah had uttered every word with his
own mouth, and he had faithfully written it down; everything was Jeremiah's own.[41]
The princes were well aware that the prophet's action would probably be resented and
punished by Jehoiakim. They said to Baruch: "Do you and Jeremiah go and hide
yourselves, and let no one know where you are." They kept the roll and laid it up in
Elishama's room; then they went to the king. They found him in his winter room, in the
inner court of the palace, sitting in front of a brasier of burning charcoal. On this fast-day
the king's mind might well be careful and troubled, as he meditated on the kind of
treatment that he, the nominee of Pharaoh Necho, was likely to receive from
Nebuchadnezzar. We cannot tell whether he contemplated resistance or had already
resolved to submit to the conqueror. In either case he would wish to act on his own
initiative, and might be anxious lest a Chaldean party should get the upper hand in
Jerusalem and surrender him and the city to the invader.
When the princes entered, their number and their manner would at once indicate to him
that their errand was both serious and disagreeable. He seems to have listened in silence
while they made their report of the incident at the door of Gemariah's chamber and their
own interview with Baruch.[42] The king sent for the roll by Jehudi, who had
accompanied the princes into the presence chamber; and on his return the same
serviceable official read its contents before Jehoiakim and the princes, whose number
was now augmented by the nobles in attendance upon the king. Jehudi had had the
advantage of hearing Baruch read the roll, but ancient Hebrew manuscripts were not
easy to decipher, and probably Jehudi stumbled somewhat; altogether the reading of
prophecies by a court-usher would not be a very edifying performance, or very gratifying
to Jeremiah's friends. Jehoiakim treated the matter with deliberate and ostentatious
contempt. At the end of every three or four columns,[43] he put out his hand for the roll,
cut away the portion that had been read, and threw it on the fire; then he handed the
remainder back to Jehudi, and the reading was resumed till the king thought fit to repeat
the process. It at once appeared that the audience was divided into two parties. When
Gemariah's father, Shaphan, had read Deuteronomy to Josiah, the king rent his clothes;
but now the writer tells us, half aghast, that neither Jehoiakim nor any of his servants
were afraid or rent their clothes, but the audience, including doubtless both court officials
and some of the princes, looked on with calm indifference. Not so the princes who had
been present at Baruch's reading: they had probably induced him to leave the roll with
them, by promising that it should be kept safely; they had tried to keep it out of the
king's hands by leaving it in Elishama's room, and now they made another attempt to
save it from destruction. They entreated Jehoiakim to refrain from open and insolent
defiance of a prophet who might after all be speaking in the name of Jehovah. But the
king persevered. The alternate reading and burning went on; the unfortunate usher's
fluency and clearness would not be improved by the extraordinary conditions under which
he had to read; and we may well suppose that the concluding columns were hurried over
in a somewhat perfunctory fashion, if they were read at all. As soon as the last shred of
parchment was shrivelling on the charcoal, Jehoiakim commanded three of his officers[44]
to arrest Jeremiah and Baruch. But they had taken the advice of the princes and were not
to be found: "Jehovah hid them."
Thus the career of Baruch's roll was summarily cut short. But it had done its work; it had
been read on three separate occasions, first before the people, then before the princes,
and last of all before the king and his court. If Jeremiah had appeared in person, he
might have been at once arrested, and put to death like Uriah. No doubt this threefold
recital was, on the whole, a failure; Jeremiah's party among the princes had listened with
anxious deference, but the appeal had been received by the people with indifference and
by the king with contempt. Nevertheless it must have strengthened individuals in the true
faith, and it had proclaimed afresh that the religion of Jehovah gave no sanction to the
policy of Jehoiakim: the ruin of Judah would be a proof of the sovereignty of Jehovah and
not of His impotence. But probably this incident had more immediate influence over the
king than we might at first sight suppose. When Nebuchadnezzar arrived in Palestine,
Jehoiakim submitted to him, a policy entirely in accordance with the views of Jeremiah.
We may well believe that the experiences of this fast-day had strengthened the hands of
the prophet's friends, and cooled the enthusiasm of the court for more desperate and
adventurous courses. Every year's respite for Judah fostered the growth of the true
religion of Jehovah.
The sequel showed how much more prudent it was to risk the existence of a roll rather
than the life of a prophet. Jeremiah was only encouraged to persevere. By the Divine
command, he dictated his prophecies afresh to Baruch, adding besides unto them many
like words. Possibly other copies were made of the whole or parts of this roll, and were
secretly circulated, read, and talked about. We are not told whether Jehoiakim ever heard
this new roll; but, as one of the many like things added to the older prophecies was a
terrible personal condemnation of the king,[45] we may be sure that he was not allowed
to remain in ignorance, at any rate, of this portion of it.
The second roll was, doubtless, one of the main sources of our present Book of Jeremiah,
and the narrative of this chapter is of considerable importance for Old Testament
criticism. It shows that a prophetic book may not go back to any prophetic autograph at
all; its most original sources may be manuscripts written at the prophet's dictation, and
liable to all the errors which are apt to creep into the most faithful work of an
amanuensis. It shows further that, even when a prophet's utterances were written down
during his lifetime, the manuscript may contain only his recollections[46] of what he said
years before, and that these might be either expanded or abbreviated, sometimes even
unconsciously modified, in the light of subsequent events. Verse 32 shows that Jeremiah
did not hesitate to add to the record of his former prophecies "many like words": there is
no reason to suppose that these were all contained in an appendix; they would often take
the form of annotations.
The important part played by Baruch as Jeremiah's secretary and representative must
have invested him with full authority to speak for his master and expound his views; such
authority points to Baruch as the natural editor of our present book, which is virtually the
"Life and Writings" of the prophet. The last words of our chapter are ambiguous, perhaps
intentionally. They simply state that many like words were added, and do not say by
whom; they might even include additions made later on by Baruch from his own
reminiscences.
In conclusion, we may notice that both the first and second copies of the roll were written
by the direct Divine command, just as in the Hexateuch and the Book of Samuel we read
of Moses, Joshua, and Samuel committing certain matters to writing at the bidding of
Jehovah. We have here the recognition of the inspiration of the scribe, as ancillary to that
of the prophet. Jehovah not only gives His word to His servants, but watches over its
preservation and transmission.[47] But there is no inspiration to write any new revelation:
the spoken word, the consecrated life, are inspired; the book is only a record of inspired
speech and action.
CHAPTER IV
THE RECHABITES
xxxv.

"Jonadab the son of Rechab shall not want a man to stand before Me for ever."—Jer.
xxxv. 19.

This incident is dated "in the days of Jehoiakim." We learn from verse 11 that it happened
at a time when the open country of Judah was threatened by the advance of
Nebuchadnezzar with a Chaldean and Syrian army. If Nebuchadnezzar marched into the
south of Palestine immediately after the battle of Carchemish, the incident may have
happened, as some suggest, in the eventful fourth year of Jehoiakim; or if he did not
appear in the neighbourhood of Jerusalem till after he had taken over the royal authority
at Babylon, Jeremiah's interview with the Rechabites may have followed pretty closely
upon the destruction of Baruch's roll. But we need not press the words "Nebuchadnezzar
... came up into the land"; they may only mean that Judah was invaded by an army
acting under his orders. The mention of Chaldeans and Assyrians suggests that this
invasion is the same as that mentioned in 2 Kings xxiv. 1, 2, where we are told that
Jehoiakim served Nebuchadnezzar three years and then rebelled against him, whereupon
Jehovah sent against him bands of Chaldeans, Syrians, Moabites, and Ammonites, and
sent them against Judah to destroy it. If this is the invasion referred to in our chapter it
falls towards the end of Jehoiakim's reign, and sufficient time had elapsed to allow the
king's anger against Jeremiah to cool, so that the prophet could venture out of his hiding-
place.
The marauding bands of Chaldeans and their allies had driven the country people in
crowds into Jerusalem, and among them the nomad clan of the Rechabites. According to
1 Chron. ii. 55, the Rechabites traced their descent to a certain Hemath, and were a
branch of the Kenites, an Edomite tribe dwelling for the most part in the south of
Palestine. These Kenites had maintained an ancient and intimate alliance with Judah, and
in time the allies virtually became a single people, so that after the Return from the
Captivity all distinction of race between Kenites and Jews was forgotten, and the Kenites
were reckoned among the families of Israel. In this fusion of their tribe with Judah, the
Rechabite clan would be included. It is clear from all the references both to Kenites and
to Rechabites that they had adopted the religion of Israel and worshipped Jehovah. We
know nothing else of the early history of the Rechabites. The statement in Chronicles that
the father of the house of Rechab was Hemath perhaps points to their having been at
one time settled at some place called Hemath near Jabez in Judah. Possibly too Rechab,
which means "rider," is not a personal name, but a designation of the clan as horsemen
of the desert.
These Rechabites were conspicuous among the Jewish farmers and townsfolk by their
rigid adherence to the habits of nomad life; and it was this peculiarity that attracted the
notice of Jeremiah, and made them a suitable object-lesson to the recreant Jews. The
traditional customs of the clan had been formulated into positive commands by Jonadab,
the son of Rechab, i.e. the Rechabite. This must be the same Jonadab who co-operated
with Jehu in overthrowing the house of Omri and suppressing the worship of Baal. Jehu's
reforms concluded the long struggle of Elijah and Elisha against the house of Omri and its
half-heathen religion. Hence we may infer that Jonadab and his Rechabites had come
under the influence of these great prophets, and that their social and religious condition
was one result of Elijah's work. Jeremiah stood in the true line of succession from the
northern prophets in his attitude towards religion and politics; so that there would be
bonds of sympathy between him and these nomad refugees.
The laws or customs of Jonadab, like the Ten Commandments, were chiefly negative: "Ye
shall drink no wine, neither ye nor your sons for ever: neither shall ye build houses, nor
sow seed, nor plant vineyards, nor have any: but all your days ye shall dwell in tents; that
ye may live many days in the land wherein ye are strangers."
Various parallels have been found to the customs of the Rechabites. The Hebrew
Nazarites abstained from wine and strong drink, from grapes and grape juice and
everything made of the vine, "from the kernels even to the husk."[48] Mohammed forbade
his followers to drink any sort of wine or strong drink. But the closest parallel is one often
quoted from Diodorus Siculus,[49] who, writing about b.c. 8, tells us that the Nabatean
Arabs were prohibited under the penalty of death from sowing corn or planting fruit trees,
using wine or building houses. Such abstinence is not primarily ascetic; it expresses the
universal contempt of the wandering hunter and herdsman for tillers of the ground, who
are tied to one small spot of earth, and for burghers, who further imprison themselves in
narrow houses and behind city walls. The nomad has a not altogether unfounded instinct
that such acceptance of material restraints emasculates both soul and body. A remarkable
parallel to the laws of Jonadab ben Rechab is found in the injunctions of the dying
highlander, Ranald of the Mist, to his heir: "Son of the Mist! be free as thy forefathers.
Own no lord—receive no law—take no hire—give no stipend—build no hut—enclose no
pasture—sow no grain."[50] The Rechabite faith in the higher moral value of their
primitive habits had survived their alliance with Israel, and Jonadab did his best to protect
his clan from the taint of city life and settled civilisation. Abstinence from wine was not
enjoined chiefly, if at all, to guard against intoxication, but because the fascinations of the
grape might tempt the clan to plant vineyards, or, at any rate, would make them
dangerously dependent upon vine-dressers and wine-merchants.
Till this recent invasion, the Rechabites had faithfully observed their ancestral laws, but
the stress of circumstances had now driven them into a fortified city, possibly even into
houses, though it is more probable that they were encamped in some open space within
the walls.[51] Jeremiah was commanded to go and bring them into the Temple, that is,
into one of the rooms in the Temple buildings, and offer them wine. The narrative
proceeds in the first person, "I took Jaazaniah," so that the chapter will have been
composed by the prophet himself. In somewhat legal fashion he tells us how he took
"Jaazaniah ben Jeremiah, ben Habaziniah, and his brethren, and all his sons, and all the
clan of the Rechabites." All three names are compounded of the Divine name Iah,
Jehovah, and serve to emphasise the devotion of the clan to the God of Israel. It is a
curious coincidence that the somewhat rare name Jeremiah[52] should occur twice in this
connection. The room to which the prophet took his friends is described as the chamber
of the disciples of the man of God[53] Hanan ben Igdaliah, which was by the chamber of
the princes, which was above the chamber of the keeper of the threshold, Maaseiah ben
Shallum. Such minute details probably indicate that this chapter was committed to writing
while these buildings were still standing and still had the same occupants as at the time
of this incident, but to us the topography is unintelligible. The "man of God" or prophet
Hanan was evidently in sympathy with Jeremiah, and had a following of disciples who
formed a sort of school of the prophets, and were a sufficiently permanent body to have
a chamber assigned to them in the Temple buildings. The keepers of the threshold were
Temple officials of high standing. The "princes" may have been the princes of Judah, who
might very well have a chamber in the Temple courts; but the term is general, and may
simply refer to other Temple officials. Hanan's disciples seem to have been in good
company.
These exact specifications of person and place are probably designed to give a certain
legal solemnity and importance to the incident, and seem to warrant us in rejecting
Reuss' suggestion that our narrative is simply an elaborate prophetic figure.[54]
After these details Jeremiah next tells us how he set before his guests bowls of wine and
cups, and invited them to drink. Probably Jaazaniah and his clansmen were aware that
the scene was intended to have symbolic religious significance. They would not suppose
that the prophet had invited them all, in this solemn fashion, merely to take a cup of
wine; and they would welcome an opportunity of showing their loyalty to their own
peculiar customs. They said: "We will drink no wine: for our father Jonadab the son of
Rechab commanded us, saying, Ye shall drink no wine, neither ye nor your sons for ever."
They further recounted Jonadab's other commands and their own scrupulous obedience
in every point, except that now they had been compelled to seek refuge in a walled city.
Then the word of Jehovah came unto Jeremiah; he was commanded to make yet another
appeal to the Jews, by contrasting their disobedience with the fidelity of the Rechabites.
The Divine King and Father of Israel had been untiring in His instruction and admonitions:
"I have spoken unto you, rising up early and speaking." He had addressed them in
familiar fashion through their fellow-countrymen: "I have sent also unto you all My
servants the prophets, rising up early and sending them." Yet they had not hearkened
unto the God of Israel or His prophets. The Rechabites had received no special revelation;
they had not been appealed to by numerous prophets. Their Torah had been simply given
them by their father Jonadab; nevertheless the commands of Jonadab had been regarded
and those of Jehovah had been treated with contempt.
Obedience and disobedience would bring forth their natural fruit. "I will bring upon Judah,
and upon all the inhabitants of Jerusalem, all the evil that I have pronounced against
them: because I have spoken unto them, but they have not heard; and I have called unto
them, but they have not answered." But because the Rechabites obeyed the
commandment of their father Jonadab, "Therefore thus saith Jehovah Sabaoth, Jonadab
the son of Rechab shall not want a man to stand before Me for ever."
Jehovah's approval of the obedience of the Rechabites is quite independent of the specific
commands which they obeyed. It does not bind us to abstain from wine any more than
from building houses and sowing seed. Jeremiah himself, for instance, would have had no
more hesitation in drinking wine than in sowing his field at Anathoth. The tribal customs
of the Rechabites had no authority whatever over him. Nor is it exactly his object to set
forth the merit of obedience and its certain and great reward. These truths are rather
touched upon incidentally. What Jeremiah seeks to emphasise is the gross, extreme,
unique wickedness of Israel's disobedience. Jehovah had not looked for any special virtue
in His people. His Torah was not made up of counsels of perfection. He had only expected
the loyalty that Moab paid to Chemosh, and Tyre and Sidon to Baal. He would have been
satisfied if Israel had observed His laws as faithfully as the nomads of the desert kept up
their ancestral habits. Jehovah had spoken through Jeremiah long ago and said: "Pass
over the isles of Chittim, and see; and send unto Kedar, and consider diligently, and see if
there be any such thing. Hath a nation changed their gods, which are yet no gods? but
My people have changed their glory for that which doth not profit."[55] Centuries later
Christ found Himself constrained to upbraid the cities of Israel, "wherein most of His
mighty works were done": "Woe unto thee, Chorazin! woe unto thee, Bethsaida! for if the
mighty works which were done in you had been done in Tyre and Sidon, they would have
repented long ago in sackcloth and ashes.... It shall be more tolerable for Tyre and Sidon
at the day of judgment than for you."[56] And again and again in the history of the
Church the Holy Spirit has been grieved because those who profess and call themselves
Christians, and claim to prophesy and do many mighty works in the name of Christ, are
less loyal to the gospel than the heathen to their own superstitions.
Buddhists and Mohammedans have been held up as modern examples to rebuke the
Church, though as a rule with scant justification. Perhaps material for a more relevant
contrast may be found nearer home. Christian societies have been charged with
conducting their affairs by methods to which a respectable business firm would not stoop;
they are said to be less scrupulous in their dealings and less chivalrous in their honour
than the devotees of pleasure; at their gatherings they are sometimes supposed to lack
the mutual courtesy of members of a Legislature or a Chamber of Commerce. The history
of councils and synods and Church meetings gives colour to such charges, which could
never have been made if Christians had been as jealous for the Name of Christ as a
merchant is for his credit or a soldier for his honour.
And yet these contrasts do not argue any real moral and religious superiority of the
Rechabites over the Jews or of unbelievers over professing Christians. It was
comparatively easy to abstain from wine and to wander over wide pasture lands instead
of living cooped up in cities—far easier than to attain to the great ideals of Deuteronomy
and the prophets. It is always easier to conform to the code of business and society than
to live according to the Spirit of Christ. The fatal sin of Judah was not that it fell so far
short of its ideals, but that it repudiated them. So long as we lament our own failures and
still cling to the Name and Faith of Christ, we are not shut out from mercy; our supreme
sin is to crucify Christ afresh, by denying the power of His gospel, while we retain its
empty form.
The reward promised to the Rechabites for their obedience was that "Jonadab the son of
Rechab shall not want a man to stand before Me for ever"; to stand before Jehovah is
often used to describe the exercise of priestly or prophetic ministry. It has been
suggested that the Rechabites were hereby promoted to the status of the true Israel, "a
kingdom of priests"; but this phrase may merely mean that their clan should continue in
existence. Loyal observance of national law, the subordination of individual caprice and
selfishness to the interests of the community, make up a large part of that righteousness
that establisheth a nation.
Here, as elsewhere, students of prophecy have been anxious to discover some literal
fulfilment; and have searched curiously for any trace of the continued existence of the
Rechabites. The notice in Chronicles implies that they formed part of the Jewish
community of the Restoration. Apparently Alexandrian Jews were acquainted with
Rechabites at a still later date. Psalm lxxi. is ascribed by the Septuagint to "the sons of
Jonadab." Eusebius[57] mentions "priests of the sons of Rechab," and Benjamin of Tudela,
a Jewish traveller of the twelfth century, states that he met with them in Arabia. More
recent travellers have thought that they discovered the descendants of Rechab amongst
the nomads in Arabia or the Peninsula of Sinai that still practised the old ancestral
customs.
But the fidelity of Jehovah to His promises does not depend upon our unearthing obscure
tribes in distant deserts. The gifts of God are without repentance, but they have their
inexorable conditions; no nation can flourish for centuries on the virtues of its ancestors.
The Rechabites may have vanished in the ordinary stream of history, and yet we can hold
that Jeremiah's prediction has been fulfilled and is still being fulfilled. No scriptural
prophecy is limited in its application to an individual or a race, and every nation
possessed by the spirit of true patriotism shall "stand before Jehovah for ever."
CHAPTER V
BARUCH
xlv.

"Thy life will I give unto thee for a prey."—Jer. xlv. 5.

The editors of the versions and of the Hebrew text of the Old Testament have assigned a
separate chapter to this short utterance concerning Baruch; thus paying an unconscious
tribute to the worth and importance of Jeremiah's disciple and secretary, who was the
first to bear the familiar Jewish name, which in its Latinised form of Benedict has been a
favourite with saints and popes. Probably few who read of these great ascetics and
ecclesiastics give a thought to the earliest recorded Baruch, nor can we suppose that
Christian Benedicts have been named after him. One thing they may all have in common:
either their own faith or that of their parents ventured to bestow upon a "man born unto
trouble as the sparks fly upward" the epithet "Blessed." We can scarcely suppose that the
life of any Baruch or Benedict has run so smoothly as to prevent him or his friends from
feeling that such faith has not been outwardly justified and that the name suggested an
unkind satire. Certainly Jeremiah's disciple, like his namesake Baruch Spinoza, had to
recognise his blessings disguised as distress and persecution.

Baruch ben Neriah is said by Josephus[58] to have belonged to a most distinguished


family, and to have been exceedingly well educated in his native language. These
statements are perhaps legitimate deductions from the information supplied by our book.
His title "scribe"[59] and his position as Jeremiah's secretary imply that he possessed the
best culture of his time; and we are told in li. 59 that Seraiah ben Neriah, who must be
Baruch's brother, was chief chamberlain (R.V.) to Zedekiah. According to the Old Latin
Version of the Apocryphal Book of Baruch (i. 1) he was of the tribe of Simeon, a
statement by no means improbable in view of the close connection between Judah and
Simeon, but needing the support of some better authority.
Baruch's relation to Jeremiah is not expressly defined, but it is clearly indicated in the
various narratives in which he is referred to. We find him in constant attendance upon the
prophet, acting both as his "scribe," or secretary, and as his mouthpiece. The relation was
that of Joshua to Moses, of Elisha to Elijah, of Gehazi to Elisha, of Mark to Paul and
Barnabas, and of Timothy to Paul. It is described in the case of Joshua and Mark by the
term "minister," while Elisha is characterised as having "poured water on the hands of
Elijah." The "minister" was at once personal attendant, disciple, representative, and
possible successor of the prophet. The position has its analogue in the service of the
squire to the mediæval knight, and in that of an unpaid private secretary to a modern
cabinet minister. Squires expected to become knights, and private secretaries hope for a
seat in future cabinets. Another less perfect parallel is the relation of the members of a
German theological "seminar" to their professor.

Baruch is first[60] introduced to us in the narrative concerning the roll. He appears as


Jeremiah's amanuensis and representative, and is entrusted with the dangerous and
honourable task of publishing his prophecies to the people in the Temple. Not long
before, similar utterances had almost cost the master his life, so that the disciple showed
high courage and devotion in undertaking such a commission. He was called to share
with his master at once the same cup of persecution—and the same Divine protection.
We next hear of Baruch in connection with the symbolic purchase of the field at
Anathoth.[61] He seems to have been attending on Jeremiah during his imprisonment in
the court of the guard, and the documents containing the evidence of the purchase were
entrusted to his care. Baruch's presence in the court of the guard does not necessarily
imply that he was himself a prisoner. The whole incident shows that Jeremiah's friends
had free access to him; and Baruch probably not only attended to his master's wants in
prison, but also was his channel of communication with the outside world.
We are nowhere told that Baruch himself was either beaten or imprisoned, but it is not
improbable that he shared Jeremiah's fortunes even to these extremities. We next hear of
him as carried down to Egypt[62] with Jeremiah, when the Jewish refugees fled thither
after the murder of Gedaliah. Apparently he had remained with Jeremiah throughout the
whole interval, had continued to minister to him during his imprisonment, and had been
among the crowd of Jewish captives whom Nebuchadnezzar found at Ramah. Josephus
probably makes a similar conjecture[63] in telling us that, when Jeremiah was released
and placed under the protection of Gedaliah at Mizpah, he asked and obtained from
Nebuzaradan the liberty of his disciple Baruch. At any rate Baruch shared with his master
the transient hope and bitter disappointment of this period; he supported him in
dissuading the remnant of Jews from fleeing into Egypt, and was also compelled to share
their flight. According to a tradition recorded by Jerome, Baruch and Jeremiah died in
Egypt. But the Apocryphal Book of Baruch places him at Babylon, whither another
tradition takes him after the death of Jeremiah in Egypt.[64] These legends are probably
mere attempts of wistful imagination to supply unwelcome blanks in history.
It has often been supposed that our present Book of Jeremiah, in some stage of its
formation, was edited or compiled by Baruch, and that this book may be ranked with
biographies—like Stanley's Life of Arnold—of great teachers by their old disciples. He was
certainly the amanuensis of the roll, which must have been the most valuable authority
for any editor of Jeremiah's prophecies. And the amanuensis might very easily become
the editor. If an edition of the book was compiled in Jeremiah's lifetime, we should
naturally expect him to use Baruch's assistance; if it first took shape after the prophet's
death, and if Baruch survived, no one would be better able to compile the "Life and
Works of Jeremiah" than his favourite and faithful disciple. The personal prophecy about
Baruch does not occur in its proper place in connection with the episode of the roll, but is
appended at the end of the prophecies,[65] possibly as a kind of subscription on the part
of the editor. These data do not constitute absolute proof, but they afford strong
probability that Baruch compiled a book, which was substantially our Jeremiah. The
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like