Download as pdf or txt
Download as pdf or txt
You are on page 1of 69

Oracle Database Programming with

Visual Basic.NET: Concepts, Designs


and Implementations Ying Bai
Visit to download the full and correct content document:
https://ebookmass.com/product/oracle-database-programming-with-visual-basic-net-c
oncepts-designs-and-implementations-ying-bai/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Clearly Visual Basic: Programming with Microsoft Visual


Basic 2010, Second Edition Diane Zak

https://ebookmass.com/product/clearly-visual-basic-programming-
with-microsoft-visual-basic-2010-second-edition-diane-zak/

Programming with Microsoft Visual Basic 2017 8th


Edition Diane Zak

https://ebookmass.com/product/programming-with-microsoft-visual-
basic-2017-8th-edition-diane-zak/

Blockchain Essentials: Core Concepts and


Implementations 1st Edition Ramchandra Sharad
Mangrulkar

https://ebookmass.com/product/blockchain-essentials-core-
concepts-and-implementations-1st-edition-ramchandra-sharad-
mangrulkar/

Oracle Autonomous Database For Dummies®, 3rd Special


Edition Lawrence Miller

https://ebookmass.com/product/oracle-autonomous-database-for-
dummies-3rd-special-edition-lawrence-miller/
Simple and Efficient Programming with C#: Skills to
Build Applications with Visual Studio and .NET 2nd
Edition Vaskaran Sarcar

https://ebookmass.com/product/simple-and-efficient-programming-
with-c-skills-to-build-applications-with-visual-studio-and-
net-2nd-edition-vaskaran-sarcar/

Simple and Efficient Programming with C# : Skills to


Build Applications with Visual Studio and .NET 2nd
Edition Vaskaran Sarcar

https://ebookmass.com/product/simple-and-efficient-programming-
with-c-skills-to-build-applications-with-visual-studio-and-
net-2nd-edition-vaskaran-sarcar-2/

Database System Concepts 6th Edition, (Ebook PDF)

https://ebookmass.com/product/database-system-concepts-6th-
edition-ebook-pdf/

Database System Concepts 7th Edition Avi Silberschatz

https://ebookmass.com/product/database-system-concepts-7th-
edition-avi-silberschatz/

Database System Concepts 7th Edition Abraham


Silberschatz

https://ebookmass.com/product/database-system-concepts-7th-
edition-abraham-silberschatz/
Oracle Database Programming with Visual Basic.NET
IEEE Press
445 Hoes Lane
Piscataway, NJ 08854

IEEE Press Editorial Board


Ekram Hossain, Editor in Chief

Jón Atli Benediktsson Xiaoou Li Jeffrey Reed


Anjan Bose Lian Yong Diomidis Spinellis
David Alan Grier Andreas Molisch Sarah Spurgeon
Elya B. Joffe Saeid Nahavandi Ahmet Murat Tekalp
Oracle Database Programming with Visual Basic.NET

Concepts, Designs, and Implementations

Ying Bai
Department of Computer Science and Engineering
Johnson C. Smith University
Charlotte, North Carolina
Copyright © 2021 by The Institute of Electrical and Electronics Engineers, Inc. All rights reserved.

Published by John Wiley & Sons, Inc., Hoboken, New Jersey.


Published simultaneously in Canada.

No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by
any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under
Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of
the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance
Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 750-4470, or on the web at
www.copyright.com. Requests to the Publisher for permission should be addressed to the Permissions Department,
John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at
http://www.wiley.com/go/permission.

Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing
this book, they make no representations or warranties with respect to the accuracy or completeness of the contents
of this book and specifically disclaim any implied warranties of merchantability or fitness for a particular purpose.
No warranty may be created or extended by sales representatives or written sales materials. The advice and
strategies contained herein may not be suitable for your situation. You should consult with a professional where
appropriate. Neither the publisher nor author shall be liable for any loss of profit or any other commercial damages,
including but not limited to special, incidental, consequential, or other damages.

For general information on our other products and services or for technical support, please contact our Customer
Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax
(317) 572-4002.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be
available in electronic formats. For more information about Wiley products, visit our web site at www.wiley.com.

Library of Congress Cataloging-in-Publication Data applied for:

ISBN: 9781119734390

Cover design by Wiley


Cover image: © metamorworks/iStock/Getty Images

Set in 9.5/12.5pt STIXTwoText by SPi Global, Pondicherry, India

10 9 8 7 6 5 4 3 2 1
This book is dedicated to my wife, Yan Wang, and my daughter, Susan (Xue) Bai.
vii

Contents

About the Author xiv


Preface xv
Acknowledgments xvii
About the Companion Website xviii

1 Introduction 1
1.1 ­Outstanding Features About This Book 2
1.2 ­Who This Book Is For 2
1.3 What This Book Covered 2
1.4 How This Book Is Organized and How to Use This Book 4
1.5 How to Use Appendices and Related Materials 6
1.6 How to Use Source Codes and Sample Database 8
1.7 Instructors and Customer Supports 9

2 Introduction to Databases 10
2.1 What Are Databases and Database Programs? 11
2.1.1 File Processing System 11
2.1.2 Integrated Databases 11
2.2 Develop a Database 12
2.3 Sample Database 13
2.3.1 Relational Data Model 13
2.3.2 Entity-Relationship (ER) Model 17
2.4 Identifying Keys 18
2.4.1 Primary Key and Entity Integrity 18
2.4.2 Candidate Key 19
2.4.3 Foreign Keys and Referential Integrity 19
2.5 Define Relationships 19
2.5.1 Connectivity 19
2.6 ER Notation 22
2.7 Data Normalization 22
2.7.1 First Normal Form (1NF) 23
2.7.2 Second Normal Form (2NF) 23
2.7.3 Third Normal Form (3NF) 24
2.8 Database Components in Some Popular Databases 25
2.8.1 Microsoft Access Databases 27
viii Contents

2.8.2 SQL Server Databases 28


2.8.3 Oracle Databases 30
2.9 Create Oracle 18c XE Sample Database 33
2.9.1 Delete the Default Database XE 34
2.9.2 Create a New Oracle 18c XE Sample Database 34
2.9.3 Connect to Our Sample Database from the Oracle SQL Developer 41
2.9.4 Create an Oracle User Account for the User Schema 42
2.9.5 Create LogIn Table 45
2.9.6 Create Faculty Table 47
2.9.7 Create Other Tables 48
2.9.8 Create Relationships Among Tables 53
2.9.9 Store Images to the Oracle 18c Express Edition Database 60
2.10 Chapter Summary 73

3 Introduction to ADO.NET 77
3.1 The ADO and ADO.NET 77
3.2 Overview of the ADO.NET 79
3.3 The Architecture of the ADO.NET 80
3.4 The Components of ADO.NET 81
3.4.1 The Data Provider 81
3.4.2 The Connection Class 84
3.4.3 The Command and the Parameter Classes 87
3.4.4 The DataAdapter Class 95
3.4.5 The DataReader Class 98
3.4.6 The DataSet Component 101
3.4.7 The DataTable Component 105
3.4.8 ADO.NET Entity Framework 111
3.5 Chapter Summary 118

4 Introduction to Language-Integrated Query (LINQ) 123


4.1 Overview of Language-Integrated Query 123
4.1.1 Some Special Interfaces Used in LINQ 124
4.1.2 Standard Query Operators 126
4.1.3 Deferred Standard Query Operators 127
4.1.4 Non-Deferred Standard Query Operators 131
4.2 Introduction to LINQ 134
4.3 The Architecture and Components of LINQ 136
4.3.1 Overview of LINQ to Objects 137
4.3.2 Overview of LINQ to DataSet 138
4.3.3 Overview of LINQ to SQL 138
4.3.4 Overview of LINQ to Entities 139
4.3.5 Overview of LINQ to XML 140
4.4 LINQ to Objects 140
4.4.1 LINQ and ArrayList 140
4.4.2 LINQ and Strings 142
4.4.3 LINQ and File Directories 145
Contents ix

4.4.4 LINQ and Reflection 148


4.5 LINQ to DataSet 149
4.5.1 Operations to DataSet Objects 150
4.5.2 Operations to DataRow Objects Using the Extension Methods 162
4.5.3 Operations to DataTable Objects 166
4.6 LINQ to Entities 166
4.6.1 The Object Services Component 167
4.6.2 The ObjectContext Component 167
4.6.3 The ObjectQuery Component 167
4.6.4 LINQ to Entities Flow of Execution 168
4.6.5 Implementation of LINQ to Entities 170
4.7 LINQ to XML 170
4.7.1 LINQ to XML Class Hierarchy 171
4.7.2 Manipulate XML Elements 172
4.7.3 Manipulate XML Attributes 175
4.7.4 Query XML with LINQ to XML 177
4.8 Visual Basic.NET Language Enhancement for LINQ 181
4.8.1 Lambda Expressions 181
4.8.2 Extension Methods 183
4.8.3 Implicitly Typed Local Variables 186
4.8.4 Query Expressions 188
4.9 LINQ To Oracle 189
4.10 Chapter Summary 190

5 Query Data from Oracle Database with Visual Basic.NET 196


­ Part I: Data Query with Visual Studio.NET Design Tools and Wizards 197
5.1 A Completed Sample Database Application Example 197
5.2 Visual Studio.NET Design Tools and Wizards 200
5.2.1 Data Components in the Toolbox Window 200
5.2.2 Data Source Window 204
5.3 Query Data from Oracle Database Using Design Tools and Wizards 212
5.3.1 Application User Interface 212
5.4 Use Visual Studio Wizards and Design Tools to Query and Display Data 217
5.4.1 Query and Display Data Using the DataGridView and Detail Controls 218
5.4.2 Use DataSet Designer to Edit the Structure of the DataSet 223
5.4.3 Bind Data to the Associated Controls in LogIn Form 225
5.4.4 Develop Codes to Query Data Using the Fill() Method 229
5.4.5 Use Return a Single Value to Query Data for LogIn Form 231
5.4.6 Develop the Codes for the Selection Form 234
5.4.7 Query Data from the Faculty Table for the Faculty Form 236
5.4.8 Develop Codes to Query Data from the Faculty Table 237
5.4.9 Query Data from the Course Table for the Course Form 242
­ Part II: Data Query with Runtime Objects 250
5.5 Introduction to Runtime Objects 250
5.5.1 Procedure of Building a Data-Driven Application Using Runtime Object 252
5.6 Query Data From Oracle Server Database Using Runtime Object 253
x Contents

5.6.1 Access to Oracle Server Database 253


5.6.2 Declare Global Variables and Runtime Objects for the Oracle Provider 255
5.6.3 Query Data Using Runtime Objects for the LogIn Form 256
5.6.4 The Coding for the Selection Form 261
5.6.5 Query Data Using Runtime Objects for the Faculty Form 261
5.6.6 Query Data Using Runtime Objects for the Course Form 268
5.6.7 Query Data Using Runtime Objects for the Student Form 277
5.7 Chapter Summary 293

6 Insert Data into Oracle Database with Visual Basic.NET 300


­ Part I: Insert Data with Visual Basic.NET Design Tools and Wizards 301
6.1 Insert Data into a Database 301
6.1.1 Insert New Records into a Database Using the TableAdapter.Insert Method 302
6.1.2 Insert New Records into a Database Using the TableAdapter.Update Method 303
6.2 Insert Data into Oracle Database Using a Sample Project InsertWizard 303
6.2.1 Create a New InsertWizard Project 303
6.2.2 Application User Interfaces 304
6.2.3 Validate Data Before the Data Insertion 305
6.2.4 Initialization Coding Process for the Data Insertion 308
6.2.5 Build the Insert Query 309
6.2.6 Develop Codes to Insert Data Using the TableAdapter.Insert Method 310
6.2.7 Develop Codes to Insert Data Using the TableAdapter.Update Method 314
6.2.8 Insert Data into the Database Using the Stored Procedures 317
­ Part II: Data Insertion with Runtime Objects 325
6.3 The General Run-Time Objects Method 326
6.4 Insert Data into the Oracle Database Using the Run-Time Object Method 327
6.4.1 Insert Data into the Faculty Table for the Oracle Database 327
6.5 Insert Data into the Database Using Stored Procedures 335
6.5.1 Insert Data into the Oracle Database Using Stored Procedures 336
6.6 Insert Data into the Database Using the LINQ To DataSet Method 345
6.6.1 Insert Data into the Oracle Database Using the LINQ to DataSet Queries 346
6.7 Chapter Summary 348

7 Data Updating and Deleting with Visual Basic.NET 355


­ Part I: Data Updating and Deleting with Visual Studio.NET Design Tools and Wizards 356
7.1 Update or Delete Data Against Oracle Databases 356
7.1.1 Updating and Deleting Data from Related Tables in a DataSet 357
7.1.2 Using TableAdapter.Update and TableAdapter.Delete Methods 357
7.1.3 Update or Delete Data Against Database Using TableAdapter.Update Method 358
7.2 Update and Delete Data For Oracle 18c XE Database 359
7.2.1 Create a New UpdataDeleteWizard Project 359
7.2.2 Application User Interfaces 360
7.2.3 Validate Data Before the Data Updating and Deleting 361
7.2.4 Build the Update and Delete Queries 361
7.2.5 Develop Codes to Update Data Using the TableAdapter DBDirect Method 363
7.2.6 Develop Codes to Update Data Using the TableAdapter.Update Method 365
Contents xi

7.2.7 Develop Codes to Delete Data Using the TableAdapter DBDirect Method 367
7.2.8 Develop Codes to Delete Data Using the TableAdapter.Update Method 368
7.2.9 Validate the Data After the Data Updating and Deleting 369
­Part II: Data Updating and Deleting with Runtime Objects 372
7.3 The Run Time Objects Method 373
7.4 Update and Delete Data for Oracle Database Using the Run Time Objects 374
7.4.1 Update Data Against the Faculty Table in the Oracle Database 375
7.4.2 Delete Data From the Faculty Table in the Oracle Database 377
7.5 Update and Delete Data against Oracle Database Using Stored Procedures 381
7.5.1 Modify the Existing Project to Create Our New Project 382
7.5.2 Create the Codes to Update and Delete Data from the Course Table 382
7.5.3 Update and Delete Data Using the LINQ to DataSet Query 392
7.6 Chapter Summary 395

8 Accessing Data in ASP.NET 401


8.1 What Is .NET Framework? 402
8.2 What Is ASP.NET? 403
8.2.1 ASP.NET Web Application File Structure 404
8.2.2 ASP.NET Execution Model 405
8.2.3 What Is Really Happened When a Web Application Is Executed? 406
8.2.4 The Requirements to Test and Run the Web Project 406
8.3 Develop ASP.NET Web Application to Select Data from Oracle Databases 407
8.3.1 Create the User Interface – LogIn Form 408
8.3.2 Develop the Codes to Access and Select Data from the Database 409
8.3.3 Validate the Data in the Client Side 413
8.3.4 Create the Second User Interface – Selection Page 415
8.3.5 Develop the Codes to Open the Other Page 415
8.3.6 Modify Codes in the LogIn Page to Transfer to the Selection Page 417
8.3.7 Create the Third User Interface – Faculty Page 418
8.3.8 Develop the Codes to Select the Desired Faculty Information 419
8.3.9 Create the Fourth User Interface – Course Page 424
8.3.10 Develop the Codes to Select the Desired Course Information 427
8.4 Develop ASP.NET Web Application to Insert Data into Oracle Databases 434
8.4.1 Develop the Codes to Perform the Data Insertion Function 435
8.4.2 Develop the Codes for the Insert Button Click Event Procedure 436
8.4.3 Validate the Data Insertion 441
8.5 Develop Web Applications to Update and Delete Data in Oracle Databases 443
8.5.1 Develop the Codes for the Update Button Click Event Procedure 443
8.5.2 Develop the Codes for the Delete Button Click Event Procedure 446
8.6 Develop ASP.NET Web Applications with LINQ to Oracle Query 457
8.6.1 Generate a New Web Project LINQWebOracle and a New LinqConnect Model 457
8.6.2 Develop the Codes for Our Web Project LINQWebOracle 462
8.7 Chapter Summary 471

9 ASP.NET Web Services 476


9.1 What Are Web Services and Their Components? 477
9.2 Procedures to Build a Web Service 478
xii Contents

9.2.1 The Structure of a Typical Web Service Project 478


9.2.2 Some Real Considerations When Building a Web Service Project 479
9.2.3 Introduction to Windows Communication Foundation (WCF) 480
9.2.4 Procedures to Build an ASP.NET Web Service 484
9.2.5 Install WCF Component with Visual Studio Installer 484
9.3 Build ASP.NET Web Service Project to Access Oracle Database 485
9.3.1 Files and Items Created in the New Web Service Project 486
9.3.2 A Feeling of the Hello World Web Service Project as it Runs 489
9.3.3 Modify the Default Namespace 492
9.3.4 Create a Base Class to Handle Error Checking for Our Web Service 493
9.3.5 Create a Customer Returned Class to Hold all Retrieved Data 493
9.3.6 Visual Basic System Class and Web Service Class 495
9.3.7 Add and Build Web Method GetOracleSelect() to the Web Services 495
9.3.8 Develop the Stored Procedure to Perform the Data Query 503
9.3.9 Use DataSet as the Returning Object for the Web Method 507
9.3.10 Build Windows‐based Web Service Clients to Consume the Web Services 510
9.3.11 Build Web‐based Web Service Clients to Consume the Web Service 519
9.3.12 Deploy the Completed Web Service to Production Servers 526
9.4 Build ASP.NET Web Service Project to Insert Data Into Oracle Databases 529
9.4.1 Create a New Web Service Project WebServiceOracleInsert 529
9.4.2 Develop Four Web Service Methods 530
9.4.3 Build Windows‐based Web Service Clients to Consume the Web Services 549
9.4.4 Build Web‐based Web Service Clients to Consume the Web Services 564
9.5 Build ASP.NET Web Service to Update and Delete Data for Oracle Database 575
9.5.1 Modify the Default Namespace and Add Database Connection String 576
9.5.2 Create Our Customer‐Built Base and Returned Classes 577
9.5.3 Create a Web Method to Call Stored Procedure to Update Student Records 578
9.5.4 Create a Web Method to Call Stored Procedure to Delete Student Records 580
9.5.5 Create a Web Method to Collect the Current Student Members 582
9.5.6 Develop Two Oracle Stored Procedures with Oracle SQL Developer 584
9.6 Build Windows-Based Web Service Clients to Consume the Web Services 590
9.6.1 Add a Web Service Reference to Our Client Project 590
9.6.2 Modify the Codes in the Form_Load Event Procedure 591
9.6.3 Build the Codes to the Update Button’s Click Event Procedure 592
9.6.4 Build the Codes to the Delete Button’s Click Event Procedure 593
9.7 Build Web-Based Web Service Clients to Consume the Web Services 596
9.7.1 Create a New ASP.NET Web Project and Add an Existing Web Page 597
9.7.2 Add a Web Service Reference and Modify the Web Form Window 597
9.7.3 Develop the Codes for the Page_Load() Event Procedure 598
9.7.4 Build the Codes Inside the Back Button’s Click Event Procedure 599
9.7.5 Add the Codes to the Update Button’s Click Event Procedure 599
9.7.6 Develop Codes for the Delete Button’s Click Event Procedure 601
9.7.7 Develop Codes for the Select Button’s Click Event Procedure 602
9.8 Chapter Summary 606
Contents xiii

Appendix A: Download and Install Oracle Database XE 18c 613


Appendix B: Download and Install Oracle SQL Developer 619
Appendix C: Download and Install DevExpress WinForms 622
Appendix D: How to Use the Sample Database 625
Appendix E: How to Export the Sample Database 628
Appendix F: Download and Install dotConnect Express 632
Appendix G: How to Use User-Defined Windows/Web Forms 637
Appendix H: Download and Install FrontPage Server Extension for Windows 10 643
Appendix I: Download and Install LinqConnect Express 646

Index 649
xiv

About the Author

Dr. YING BAI is a Professor in the Department of Computer Science and Engineering at Johnson
C. Smith University. His special interests include: artificial intelligences, soft computing, mixed-
language programming, fuzzy logic and deep learning, robotic controls, robots calibrations, and
database programming.
His industry experience includes positions as software engineer and senior software engineer at
companies such as Motorola MMS, Schlumberger ATE Technology, Immix TeleCom, and Lam
Research.
Since 2003, Dr. Bai has published sixteen (16) books with publishers such as Prentice Hall, CRC
Press LLC, Springer, Cambridge University Press, and Wiley IEEE Press. The Russian translation
of his first book titled Applications Interface Programming Using Multiple Languages was published
by Prentice Hall in 2005. The Chinese translation of his eighth book titled Practical Database
Programming with Visual C#.NET was published by Tsinghua University Press in China in 2011.
Most books are about software programming, serial port programming, fuzzy logic controls in
industrial applications, microcontroller controls and programming as well as classical and modern
controls on microcontrollers.
During recent years, Dr. Bai has also published more than sixty (60) academic research papers in
IEEE Trans. Journals and International conferences.
xv

Preface

Databases have become an integral part of our modern-day life. We are an information-driven
society. Database technology has a direct impact on our daily lives. Decisions are routinely made
by organizations based on the information collected and stored in the databases. A record com-
pany may decide to market certain albums in selected regions based on the music preference of
teenagers. Grocery stores display more popular items at the eye level and reorders are based on the
inventories taken at regular intervals. Other examples include patients’ records in hospitals, cus-
tomers’ account information in banks, book orders by the libraries, club memberships, auto part
orders, and winter cloth stock by department stores, and many others.
In addition to database management systems, in order to effectively apply and implement data-
bases in real industrial or commercial systems, a good Graphic User Interface (GUI) is needed to
allow users to access and manipulate their records or data in databases. Visual Basic.NET is an
ideal candidate to be selected to provide this GUI functionality. Unlike other programming lan-
guages, Visual Basic.NET is a kind of language that has advantages such as easy-to-learn and easy-
to-be-understood with little learning curves. In the beginning of Visual Studio.NET 2005, Microsoft
integrated a few programming languages such as Visual C++, Visual Basic, C#, and Visual J# into
a dynamic model called .NET Framework that makes Internet and Web programming easy and
simple, and any language integrated in this model can be used to develop professional and efficient
Web applications that can be used to communicate with others via Internet. ADO.NET and ASP.
NET are two important submodels of .NET Framework. The former provides all components,
including the Data Providers, DataSet, and DataTable, to access and manipulate data against dif-
ferent databases. The latter provides support to develop Web applications and Web services in ASP.
NET environment to allow users to exchange information between clients and servers easily and
conveniently.
This book is mainly designed for college students and software programmers who want to
develop practical and commercial database programming with Visual Basic.NET and relational
database such as Oracle XE 18c. The book provides a detailed description about the practical con-
siderations and applications in database programming with Visual Basic.NET 2019 with authentic
examples and detailed explanations. More important, a new writing style is developed and imple-
mented in this book, combined with real examples, to provide readers with a clear picture as how
to handle the database programming issues in Visual Basic.NET 2019 environment.
The outstanding features of this book include, but no limited to:
1) A novel writing style is adopted to try to attract students’ or beginning programmers’ interest in
learning and developing practical database programs and to avoid the headache caused by
using huge blocks of codes in the traditional database programming books.
xvi Preface

2) Updated database programming tools and components are covered in the book, such as .NET
Framework 4.7, LINQ, ADO.NET 4.6, and ASP.NET 4.6, to enable readers to easily and quickly
learn and master advanced techniques in database programming and develop professional and
practical database applications.
3) A real completed sample Oracle XE 18c database CSE_DEPT is provided and used for the entire
book. Step by step, a detailed illustration and description about how to design and build a prac-
tical relational database are provided.
4) Covered both fundamental and advanced database-programming techniques to the conveni-
ence of both beginning students and experienced programmers.
5) All projects can be run in Microsoft Visual Studio.NET 2019 with Oracle XE 18c database.
6) Good textbook for college students, good reference book for programmers, software engineers,
and academic researchers.
I sincerely hope that this book can provide useful and practical help and guide to all readers or
users who adopted this book, and I will be more than happy to know that you guys can develop and
build professional and practical database applications with the help of this book.

Ying Bai
xvii

Acknowledgments

First, a special thanks to my wife, Yan Wang, for I could not have finished this book without her
sincere encouragement and support.
Special thanks also to Dr. Satish Bhalla, a specialist in database programming and management,
especially in SQL Server, Oracle, and DB2, who spent a lot of time preparing materials for Chapter 2.
Many thanks to the Senior Editor, Mary Hatcher, who made this book available to the public,
without whose perseverance and hard work this book would not be available in the market. Thanks
should also go to the entire editorial team for all their contributions which made it possible to
publish this book.
Thanks are extended to the following book reviewers for their valuable suggestions and inputs:
●● Dr. Jiang (Linda) Xie, Professor, Department of Electrical and Computer Engineering, University
of North Carolina at Charlotte.
●● Dr. Dali Wang, Professor, Department of Physics and Computer Science, Christopher Newport
University.
●● Dr. Daoxi Xiu, Application Analyst Programmer, North Carolina Administrative Office of the
Courts.
Finally, but not the least, I would like to express my gratitude to all the people who supported me
in completing this book.
xviii

About the Companion Website

This book is accompanied by a companion website:

www.wiley.com/go/bai-VB-Oracle

The book companion website includes:


1) Instructor materials (accessible only by Instructors)
a) HW DB Project Solutions
b) HW Question Solutions
c) Images
d) Sample Database
e) Teaching-PPT
2) Student materials
a) Class DB Projects
b) Images
c) Sample Database
d) VB Forms
1

Introduction

For many years during my teaching Visual Basic.NET programming and database-related
­programming courses in my college, I found that it is not easy to find a good textbook for this topic
and I had to combine a few different professional books together as references to teach these
courses. Most of those books are specially designed for programmers or software engineers, which
cover a lot of programming strategies and huge blocks of codes, which is a terrible headache to the
college students or beginning programmers who are new to the Visual Basic.NET and database
programming. I have to prepare my class presentations and figure out all home works and exer-
cises for my students. I dream that one day I could find a good textbook that is suitable for the
college students or beginning programmers and could be used to help them to learn and master the
database programming with Visual Basic.NET easily and conveniently. Finally, I decided that I
need to do something for this dream myself after a long time waiting.
Another reason for me to have this idea is the job market. As you know, most industrial and com-
mercial companies in US belong to database application businesses such as manufactures, banks,
hospitals, and retails. Majority of them need professional people to develop and build database-
related applications but not database management and design systems. To enable our students to
become good candidates for those companies, we need to create a book like this one.
Unlike most of database programming books in the current market, which discuss and present
the database programming techniques with huge blocks of programming codes from the first page
to the last page, this book tries to use a new writing style to show readers, especially to the college
students, how to develop professional and practical database programs with Visual Basic.NET by
using Visual Studio.NET Design Tools and Wizards related to ADO.NET and to apply codes that
are auto-generated by various Wizards. By using this new style, the over headache caused by using
huge blocks of programming codes can be removed; instead, a simple and easy way to create
­database programs using the Design Tools can be taken to attract students’ learning interest and
furthermore to enable students to build professional and practical database programming in more
efficient and interesting ways.
There are so many different database-programming books available on the market, but rarely
can you find a book like this one, which implemented a novel writing style to attract the students’
learning interests in this topic. To meet the needs of some experienced or advanced students or
software engineers, the book contains two programming methods: the interesting and easy-to-
learn fundamental database programming method – Visual Studio.NET Design Tools and

Oracle Database Programming with Visual Basic.NET: Concepts, Designs, and Implementations, First Edition. Ying Bai.
© 2021 The Institute of Electrical and Electronics Engineers, Inc. Published 2021 by John Wiley & Sons, Inc.
Companion website: www.wiley.com/go/bai-VB-Oracle
2 1 Introduction

Wizards – and the advanced database programming method – runtime object method. In the
­second method, all database-related objects are created and applied during or when your project is
running by utilizing quite a few blocks of codes.

1.1 ­Outstanding Features About This Book

1) All programming projects can be run in Microsoft Visual Studio.NET 2019 with Oracle XE 18c
databases.
2) A novel writing style is adopted to try to attract students’ or beginning programmers’ interests
in learning and developing practical database programs and to avoid the headache caused by
using huge blocks of codes in the traditional database programming books.
3) Updated database programming tools and components are covered in the book, such as .NET
Framework 4.7, LINQ, ADO.NET 4.6, and ASP.NET 4.7, to enable readers to easily and quickly
learn and master advanced techniques in database programming and develop professional and
practical database applications.
4) A real completed sample database CSE_DEPT with Oracle XE 18c database engine is provided
and used for the entire book. Step by step, a detailed illustration and description about how to
design and build a practical relational database are provided.
5) Covered both fundamental and advanced database programming techniques to convenience
both beginning students and experienced programmers.
6) Provides homework and exercises for students and teaching materials for instructors, and these
enable students to understand what they learned better by doing something themselves and
allow instructors to organize and prepare their courses easily and rapidly.
7) Good textbook for college students, good reference book for programmers, software engineers,
and academic researchers.

1.2 ­Who This Book Is For

This book is designed for college students and software programmers who want to develop practi-
cal and commercial database programming with Visual Basic.NET and relational databases such
as Oracle XE 18c. Fundamental knowledge and understanding on Visual Basic.NET and Visual
Studio.NET IDE is assumed.

1.3 ­What This Book Covered

Nine (9) chapters are included in this book. The contents of each chapter can be summarized as
below.
●● Chapter 1 provides an introduction and summarization to the whole book.
●● Chapter 2 provides detailed discussions and analyses of the structure and components about
relational databases. Some key technologies in developing and designing database are also given
and discussed in this part. The procedure and components used to develop a practical relational
database with Oracle XE 18c are analyzed in detailed with some real data tables in our sample
database CSE_DEPT.
1.3 ­What This Book Covere 3

●● Chapter 3 provides an introduction to the ADO.NET, which includes the architectures, ­organizations,
and components of the ADO.NET. Detailed discussions and descriptions are provided in this chap-
ter to give readers both fundamental and practical ideas and pictures in how to use components in
ADO.NET to develop professional data-driven applications. Two ADO.NET architectures are dis-
cussed to enable users to follow the directions to design and build their preferred projects based on
the different organizations of the ADO.NET. Four popular data providers, such as OleDb, ODBC,
SQL Server, and Oracle, are discussed. The basic ideas and implementation examples of DataTable
and DataSet are also analyzed and described with some real coding examples.
●● Chapter 4 provides detailed discussions and analyses about the Language-Integrated Query
(LINQ), which includes LINQ to Objects, LINQ to DataSet, LINQ to Entities, and LINQ to XML.
An introduction to LINQ general programming guide is provided in the first part of this chapter.
Some popular interfaces widely used in LINQ, such as IEnumerable, IEnumerable(Of T),
IQueryable and IQueryable(Of T), and Standard Query Operators (SQO) including the deferred
and non-deferred SQO, are also discussed in that part. An introduction to LINQ Query is given
in the second section of this chapter. Following this introduction, a detailed discussion and anal-
ysis about the LINQ queries that are implemented for different data sources is provided in detail
with quite a few example projects.
●● Starting from Chapter 5, the real database programming techniques with Visual Basic.NET such
as data selection queries are provided and discussed. Two parts are covered in this chapter: Part
I contains the detailed descriptions in how to develop professional data-driven applications with
the help of the Visual Studio.NET design tools and wizards with some real projects. This part
contains a lot of hiding codes that are created by Visual Basic.NET automatically when using
those design tools and wizards. Therefore, the coding job for this part is very simple and easy.
Part II covers an advanced technique, the runtime object method, in developing and building
professional data-driven applications. Detailed discussions and descriptions about how to build
professional and practical database applications using this runtime object method are provided
combined with four (4) real projects.
●● Chapter 6 provides detailed discussions and analyses about three popular data insertion meth-
ods with Oracle XE 18c database:
1) Using TableAdapter’s DBDirect methods TableAdapter.Insert() method.
2) Using the TableAdapter’s Update() method to insert new records that have already been
added into the DataTable in the DataSet.
3) Using the Command object’s ExecuteNonQuery() method.
This chapter is also divided into two parts: Methods 1 and 2 are related to Visual Studio.NET
design tools and wizards and therefore are covered in Part I. The third method is related to runt-
ime object and therefore it is covered in Part II. Four (4) real projects are used to illustrate how
to perform the data insertion into the Oracle XE 18c database. Some professional and practical
data validation methods are also discussed in this chapter to confirm the data insertion.
●● Chapter 7 provides discussions and analyses on three popular data updating and deleting meth-
ods with four real project examples:
1) Using TableAdapter DBDirect methods such as TableAdapter.Update() and TableAdapter.
Delete() to update and delete data directly again in the databases.
2) Using TableAdapter.Update() method to update and execute the associated TableAdapter’s
properties such as UpdateCommand or DeleteCommand to save changes made for the table
in the DataSet to the table in the database.
4 1 Introduction

3) Using the runtime object method to develop and execute the Command’s method
ExecuteNonQuery() to update or delete data again in the database directly.
This chapter is also divided into two parts: Methods 1 and 2 are related to Visual Studio.NET
design tools and wizards and therefore are covered in Part I. The third method is related to runt-
ime object and it is covered in Part II. Four (4) real projects are used to illustrate how to perform
the data updating and deleting against the database Oracle XE 18c. Some professional and prac-
tical data validation methods are also discussed in this chapter to confirm the data updating and
deleting actions. The key points in performing the data updating and deleting actions against a
relational database, such as the order to execute data updating and deleting between the parent
and child tables, are also discussed and analyzed.
●● Chapter 8 provides introductions and discussions about the developments and implementations
of ASP.NET Web applications in Visual Basic.NET 2019 environment. At the beginning of
Chapter 8, a detailed and complete description about the ASP.NET and the .NET Framework is
provided, and this part is especially useful and important to students or programmers who do
not have any knowledge or background in the Web application developments and implementa-
tions. Following the introduction section, a detailed discussion on how to install and configure
the environment to develop the ASP.NET Web applications is provided. Some essential tools
such as the Web server, IIS, and FrontPage Server Extension 2000 as well as the installation pro-
cess of these tools are introduced and discussed in detail. Starting from Section 8.3, the detailed
development and building process of ASP.NET Web applications to access the Oracle databases
are discussed with four (4) real Web application projects. One popular database Oracle XE 18c is
utilized as the target databases for those development and building processes.
●● Chapter 9 provides introductions and discussions about the developments and implementations
of ASP.NET Web services in Visual Basic.NET 2019 environment. A detailed discussion and
analysis about the structure and components of the Web services is provided at the beginning of
this chapter. One of the most popular databases, Oracle XE 18c, is discussed and used for three
kinds of example Web service projects, which include:
1) WebServiceOracleSelect
2) WebServiceOracleInsert
3) WebServiceOracleUpdateDelete
Each Web service contains different Web methods that can be used to access different databases
and perform the desired data actions such as Select, Insert, Update, and Delete via the Internet. To
consume those Web services, different Web service client projects are also developed in this chap-
ter. Both Windows-based and Web-based Web service client projects are discussed and built for
each kind of Web services listed earlier. Totally, nine (9) projects, including the Web service and the
associated Web service client projects, are developed in this chapter. All projects have been
debugged and tested and can be run in most popular Windows compatible operating systems, such
as Windows XP, Windows 7/8, and Windows 10.

1.4 ­How This Book Is Organized and How to Use This Book

This book is designed for both college students who are new to database programming with
Visual Basic.NET and professional database programmers who has professional experience on
this topic.
1.4 ­How This Book Is Organized and How to Use This Boo 5

Level I

Chapter 2 Level II

Chapters 3 & 4 Chapters 3 & 4

Part I Part II
Chapter 5 Chapter 5

Part I Part II
Chapter 6 Chapter 6

Part I Part II
Chapter 7 Chapter 7
Optional
Chapter 8 Chapter 8

Chapter 9 Chapter 9

Figure 1.1 Two study levels in the book.

Chapters 2~4 provide the fundamentals on database structures and components, ADO.NET
and LINQ components. Chapters 5~7 each is divided into two parts: fundamental part and
advanced part. The data-driven applications developed with design tools and wizards provided
by Visual Studio.NET, which can be considered as the fundamental part, have less coding loads
and therefore they are more suitable to students or programmers who are new to the database
programming with Visual Basic.NET. Part II contains the runtime object method and it covers a
lot of coding developments to perform the different data actions against the database, and this
method is more flexible and convenient to experienced programmers even a lot of coding jobs is
concerned.
Chapters 8 and 9 give a full discussion and analysis about the developments and implementa-
tions of ASP.NET Web applications and Web services. These technologies are necessary to students
and programmers who want to develop and build Web applications and Web services to access and
manipulate data via Internet.
Based on the organization of this book we described earlier, this book can be used as two catego-
ries such as Level I and Level II, which is shown in Figure 1.1.
For undergraduate college students or beginning software programmers, it is highly recom-
mended to learn and understand the contents of Chapters 2~4 and Part I of Chapters 5~7, since
those are fundamental knowledge and techniques in database programming with Visual Basic.
NET. Regarding Chapters 8 and 9, it is optional to instructors and it depends on the time and
schedule available to instructors.
For experienced college students or software programmers who have already had some knowl-
edge and techniques in database programming, it is recommended to learn and understand the
contents of Part II of Chapters 5~7 as well as Chapters 8 and 9 since the runtime objects method
and some sophisticated database programming techniques, such as joined-table query and nested
stored procedures, are discussed and illustrated in those chapters with real examples. Also the ASP.
NET Web applications and ASP.NET Web services are discussed and analyzed with many real data-
base program examples for Oracle XE 18c database.
6 1 Introduction

1.5 ­How to Use Appendices and Related Materials

Totally, nine (9) Appendices, Appendices A~I, are provided with the book to assist and help readers
to easily and correctly download and install all required and necessary software and tools to build
desired practical database projects. These Appendices provide crystal clear directions for readers to
enable them to smoothly go through the entire installing and setup processes for each kind of soft-
ware and development tool and make them ready to be used to build professional and practical
database applications. The main functions and directions provided by these Appendices include:
–– Appendix A: Download and Install Oracle Database 18c XE. Provides a
complete and accurate direction to help users to complete downloading and installing this
Oracle XE 18c Database with its engine.
–– Appendix B: Download and Install Oracle SQL Developer. Provides an
accurate direction to help users to complete downloading and installing this Oracle SQL
Developer. This tool is a key component to build and develop any customer Oracle database,
including our sample database CSE_DEPT with five data tables and keys.
–– Appendix C: Download and Install DevExpress WinForms. Provides a com-
plete direction to help users to complete downloading and installing this third-party tool. By
using this tool, users can directly and conveniently insert any image into any table in Oracle
database without any coding process. This product is a 30-day free trial version without any
charge to the user.
–– Appendix D: How to Use the Sample Database. To assist readers to quickly and
easily build professional database application projects, a sample database, CSE_DEPT, is pro-
vided and used for entire book. This sample database is used to simulate a computer science
and engineering department with five tables, LogIn, Faculty, Course, Student,
and StudentCourse. This Appendix provides a clear picture to show readers how to down-
load and duplicate this sample database in just some button clicks. Indeed, by using this
Appendix and following up the directions, one can easily and quickly build this sample data-
base without spending much time and efforts! It greatly simplifies the generation and building
process of this sample database and therefore provides a quick shortcut for readers.
–– Appendix E: How to Export the Sample Database. Opposite to Appendix D,
this Appendix provides a way to show readers how to export our sample database CSE_DEPT
to enable other users to import it to their blank database to simplify this database-building
process. By following up the directions provided by this Appendix, readers can easily and
quickly export their database to enable other users to import and make that database as their
database. How easy it is!
–– Appendix F: Download and Install dotConnect Express. This is a free-ver-
sion third-party product that provides a data drive for Oracle data provider. To access an Oracle
database from any programming environment, including Visual Basic.NET, a data drive is
necessary to work as a translator or a bridge to setup up a connection between Visual Basic.
NET and Oracle database engine. This Appendix provides a clear and complete direction to
enable readers to quickly setup this connection.
–– Appendix G: How to Use User-Defined Windows/Web Forms. To assist readers
to speed up their database project developments, all Windows Forms and Web Pages used for
all projects built in this book have been developed. Readers can use any of them by just simply
adding them into their projects by using Add|Existing Item menu item. All built
Windows Forms, including the LogIn Form, Selection Form, Faculty Form,
1.5 ­How to Use Appendices and Related Material 7

Course Form, and Student Form, and all built Web Pages, including the LogIn Page,
Selection Page, Faculty Page, Course Page, and Student Page, can be found from a folder VB
Forms\Windows and VB Forms\Web, which is located under the Students folder at the
Wiley ftp site (refer to Figure 1.2).
–– Appendix H: Download and Install FrontPage Server Extension for Windows 10.
To run any project developed in Chapters 8 and 9, one needs to use Internet Information Services
(IIS) provider. The FrontPage Server Extension can be considered as an administrator for IIS. To uti-
lize the IIS more effectively and efficiently, it is recommend installing this extension if possible.

For instructors:

Instructor materials are available upon request from wwww.wiley.com/go/bai-VB-Oracle/Instructors

HW DB projects Images HW question solutions


Sample database solutions Teaching-PPT

CSE_DEPT Chapter 1.ppt HW_Solution.pdf


Chapter 5 Chapter 2.ppt Faculty
2 Projects
Chapter 3.ppt 12-Faculty
Chapter 6 images
3 Projects Chapter 4.ppt

Chapter 7 Chapter 5.ppt


2 Projects Chapter 6.ppt Students
Chapter 8 Chapter 7.ppt 8-Student
4 Project images
Chapter 8.ppt
Chapter 9 Chapter 9.ppt
6 Projects

For students:

Learning materials are free to access via the site www.wiley.com/go/bai-VB-Oracle/Students

Class DB projects

Sample database I mages


VB forms
Chapter 2
CSE_DEPT 1 Project
Window Faculty
Chapter 4
12 Projects
Login form 13-Faculty
Faculty form Chapter 5 images
4 Projects
Course form
Student form Chapter 6
4 Projects Students
Selection form
Chapter 7 8-Student
Web 4 Projects images
Login page
Chapter 8
Faculty page 4 Projects
Course page
Chapter 9
Student page 9 Projects
Selection page

Figure 1.2 Book-related materials on Web site.


8 1 Introduction

–– Appendix I: Download and Install LinqConnect Express. This is a free-


version third-party product that provides a drive for LINQ to Oracle. To access and manipulate
data records in an Oracle database via LINQ to Oracle, one needs to use some third-party tool
or drive to setup a connection between any programming environment, including Visual
Basic.NET, and the Oracle database engine. This Appendix provides a clear and complete
direction to enable readers to quickly setup this connection and use this LINQ to Oracle tech-
nique to develop and build professional database applications.

1.6 ­How to Use Source Codes and Sample Database

All source codes in each project developed in this book are available and open to publics, and all
projects are categorized and stored into the associated chapters, which are located at a folder
Class DB Projects that is under the Students folder at the Wiley ftp site www.wiley.com/
go/bai-VB-Oracle. You can copy or download those codes into your computer and run each project
as you like. To successfully run those projects, the following conditions must be met:
●● Visual Studio.NET 2019 or higher must be installed in your computer.
●● The database management system, Oracle Database Configuration Assistant,
must be installed in your computer.
●● The sample database, CSE_DEPT, must be installed in your computer in the appropriate
folders.
●● To run projects developed in Chapters 8 and 9, in addition to conditions listed above, an Internet
Information Services (IIS) such as FrontPage Server Extension 2000 or 2002 must be installed in
your computer and it works as a pseudo server for those projects.
●● Some third-party drives and tools, such as DevExpress WinForms, dotConnect for Oracle,
LinqConnect Express, and Oracle SQL Developer, should have been installed in your computer.
All related teaching and learning materials, including the sample database, example projects,
homework solutions, faculty and student images, as well as sample Windows forms and Web
pages, can be found from the associated folders, Instructors or Students, located at the
Wiley ftp site www.wiley.com/go/bai-VB-Oracle, as shown in Figure 1.2.
These materials are categorized and stored at different folders in two different sites based on the
teaching purpose (for instructors) and learning purpose (for students):
1) Sample Database Folder: Contains our sample database, CSE_DEPT (Oracle XE 18c) with
five (5) tables. Refer to Appendix D to get details in how to use this database for your applica-
tions or sample projects.
2) Class DB Projects Folder: Contains all sample projects developed in the book. Projects are
categorized and stored at different Chapter subfolder based on the book chapter sequence.
Readers can directly use the codes and GUIs of those projects by downloading them from this
folder that is located under the Students folder at the Wiley ftp site.
3) Images Folder: Contains all sample faculty image files (under the Images\Faculty sub-
folder) and all student image files (under the Images\Students subfolder) used in all sample
projects in the book. Readers can copy and paste those image files to their projects to use them.
4) VB Forms Folder: Contains all sampled Windows-based Forms (under the VB Forms\
Window subfolder) and Web-based Pages (under the VB Forms\Web subfolder) developed
and implemented in all sample projects in the book. Readers can use those Forms or Pages by
1.7 ­Instructors and Customer Support 9

adding them into their real projects with the Add|Existing Item menu item in the Visual
Studio.NET environment.
5) Teaching-PPT Folder: Contains all MS-PPT teaching slides for each chapter.
6) HW Question Solutions Folder: Contains selected solutions for the homework
Questions developed and used in the book. The solutions are categorized and stored at the dif-
ferent Chapter subfolder based on the book chapter sequence.
7) HW DB Project Solutions Folder: Contains all solutions for the homework Exercises
developed and used in the book. The project solutions are categorized and stored at the different
Chapter subfolder based on the book chapter sequence.
Folders 1~4 belong to learning materials for students; therefore, they are located at the sub-
folder Students at the site: www.wiley.com/go/bai-VB-Oracle. Folders 1~3 and 5~7 belong to
teaching materials for instructors, they are located at the sub-folder Instructors at the same
site (password protected) and available upon requests by instructors.

1.7 ­Instructors and Customer Supports

The teaching materials for all chapters have been extracted and represented by a sequence of
Microsoft Power Point files, each file for one chapter. The interested instructors can find them from
the folder Teaching-PPT that is located at a sub-folder Instructors at the site www.wiley.
com/go/bai-VB-Oracle and those instructor materials are available upon request from the book’s
listing on that site (password protected).
A selected homework Questions solution and all homework Exercise solutions are also available
upon request from the site. E-mail support is available to readers of this book. When you send
e-mail to us, please provide the following information:
●● The detailed description about your problems, including the error message and debug message,
as well as the error or debug number if it is provided.
●● Your name, job title, and company name.
●● Please send all questions to the e-mail address: ybai@jcsu.edu.
Detailed structure and distribution of all book-related materials in the Wiley site, including the
teaching and learning materials, are shown in Figure 1.2.
All projects in the folder Instructors|HW DB Project Solutions are different from
those in the Students folder since the former contained solutions to projects in the Exercises
part, but the latter have no solutions.
10

Introduction to Databases
Ying Bai and Satish Bhalla

Databases have become an integral part of our modern day life. Today, we are an ­information-driven
society. Large amounts of data are generated, analyzed, and converted into different information
at each moment. A recent example of biological data generation is the Human Genome project
that was jointly sponsored by the Department of Energy (DOE) and the National Institute of
Health (NIH). Many countries participated in this venture for more than 10 years. The project was
a tremendous success. It was completed in 2003 and resulted in the generation of huge amount of
genome data, currently stored in databases around the world. The scientists will be analyzing this
data in years to come.
Database technology has a direct impact on our daily lives. Decisions are routinely made by
organizations based on the information collected and stored in the databases. A record company
may decide to market certain albums in selected regions based on the music preference of teenag-
ers. Grocery stores display more popular items at the eye level, and reorders are based on the inven-
tories taken at regular intervals. Other examples include book orders by the libraries, club
memberships, auto part orders, winter cloth stock by department stores, and many others.
Database management programs have been in existence since the sixties. However, it was not
until the seventies when E. F. Codd proposed the then revolutionary Relational Data Model that
database technology really took off. In the early eighties, it received a further boost with the arrival
of personal computers and microcomputer-based data management programs like dBase II (later
followed by dBase III and IV). Today, we have a plethora of vastly improved programs for PCs and
mainframe computers, including Microsoft Access, SQL Server, IBM DB2, Oracle, Sequel Server,
MySQL, and others.
This chapter covers the basic concepts of database design followed by implementation of a spe-
cific relational database to illustrate the concepts discussed here. The sample database, CSE_DEPT,
is used as a running example. The database structure is shown by using Microsoft Access, Microsoft
SQL Server, and Oracle databases with a real Oracle 18c XE database sample in details. The topics
discussed in this chapter include:
●● What are databases and database programs?
–– File Processing System
–– Integrated Databases
●● Various approaches to developing a Database
●● Relational Data Model and Entity-Relationship (ER) Model

Oracle Database Programming with Visual Basic.NET: Concepts, Designs, and Implementations, First Edition. Ying Bai.
© 2021 The Institute of Electrical and Electronics Engineers, Inc. Published 2021 by John Wiley & Sons, Inc.
Companion website: www.wiley.com/go/bai-VB-Oracle
2.1 ­What Are Databases and Database Programs 11

●● Identifying Keys
–– Primary Keys, Foreign Keys, and Referential Integrity
●● Defining Relationships
●● Normalizing the Data
●● Implementing the Relational Sample Database
–– Create Microsoft SQL Server 2017 Express Sample Database

2.1 ­What Are Databases and Database Programs?

A modern day database is a structured collection of data stored in a computer. The term structured
implies that each record in the database is stored in a certain format. For example, all entries in a
phone book are arranged in a similar fashion. Each entry contains a name, an address, and a telephone
number of a subscriber. This information can be queried and manipulated by database programs. The
data retrieved in answer to queries becomes information that can be used to make decisions. The data-
bases may consist of a single table or related multiple tables. The computer programs used to create,
manage, and query databases are known as a DataBase Management Systems (DBMSs). Similar to the
databases, the DBMSs vary in complexity. Depending on the need of a user, one can use either a simple
application or a robust program. Some examples of these programs were given earlier.

2.1.1 File Processing System


File processing system (FPS) is a precursor of the integrated database approach. The records for a
particular application are stored in a file. An application program is needed to retrieve or manipulate
data in this file. Thus, various departments in an organization will have their own file processing
systems with their individual programs to store and retrieve data. The data in various files may be
duplicated and not available to other applications. This causes redundancy and may lead to inconsist-
ency, meaning that various files that supposedly contain the same information may actually contain
different data values. Thus, duplication of data creates problems with data integrity. Moreover, it is
difficult to provide access to multiple users with the file processing systems without granting them
access to the respective application programs, which manipulate the data in those files.
The FPS may be advantageous under certain circumstances. For example, if data is static and a
simple application will solve the problem, a more expensive DBMS is not needed. For example, in
a small business environment, you want to keep track of the inventory of the office equipment
purchased only once or twice a year. The data can be kept in an Excel spreadsheet and manipulated
with ease from time to time. This avoids the need to purchase an expensive database program and
hiring a knowledgeable database administrator. Before the DBMS’s became popular, the data was
kept in files and application programs were developed to delete, insert, or modify records in the
files. Since specific application programs were developed for specific data
These programs lasted for months or years before modifications were necessitated by business needs.

2.1.2 Integrated Databases


A better alternative to a file processing system is an integrated database approach. In this environ-
ment, all data belonging to an organization is stored in a single database. The database is not a
mere collection of files; there is a relation between the files. Integration implies a logical relation-
ship, usually provided through a common column in the tables. The relationships are also stored
12 2 Introduction to Databases

within the database. A set of sophisticated programs known as DBMS is used to store, access, and
manipulate the data in the database. Details of data storage and maintenance are hidden from the
user. The user interacts with the database through the DBMS. A user may interact either directly
with the DBMS or via a program written in a programming language such as Visual C++, Java,
Visual Basic, or Visual C#. Only the DBMS can access the database. Large organizations employ
Database Administrators (DBA’s) to design and maintain large databases.
There are many advantages of using an integrated database approach over that of a file ­processing
approach:
1) Data sharing: The data in the database is available to a large numbers of users who can access
the data simultaneously and create reports and manipulate the data given proper authorization
and rights.
2) Minimizing data redundancy: Since all the related data exists in a single database, there is a
minimal need of data duplication. The duplication is needed to maintain relationship between
various data items.
3) Data consistency and data integrity: Reducing data redundancy will lead to data consist-
ency. Since data is stored in a single database, enforcing data integrity becomes much easier.
Furthermore, the inherent functions of the DBMS can be used to enforce the integrity with
minimum programming.
4) Enforcing standards: DBAs are charged with enforcing standards in an organization. DBA
takes into account the needs of various departments and balances it against the overall need of
the organization. DBA defines various rules such as documentation standards, naming conven-
tions, update and recovery procedures etc. It is relatively easy to enforce these rules in a Database
System, since it is a single set of programs which is always interacting with the data files.
5) Improving security: Security is achieved through various means such as controlling access to
the database through passwords, providing various levels of authorizations, data encryption,
providing access to restricted views of the database etc.
6) Data independence: Providing data independence is a major objective for any database system.
Data independence implies that even if the physical structure of a database changes, the applica-
tions are allowed to access the database as before the changes were implemented. In other words,
the applications are immune to the changes in the physical representation and access techniques.
The downside of using an integrated database approach has mainly to do with exorbitant costs
associated with it. The hardware, the software, and maintenance are expensive. Providing security,
concurrency, integrity, and recovery may add further to this cost. Furthermore, since DBMS
­consists of a complex set of programs, trained personnel are needed to maintain it.

2.2 ­Develop a Database

Database development process may follow a classical Systems Development Life Cycle.
1) Problem Identification – Interview the user, identify user requirements, and perform pre-
liminary analysis of user needs.
2) Project Planning – Identify alternative approaches to solving the problem. Does the project
need a database? If so define the problem. Establish scope of the project.
3) Problem Analysis – Identify specifications for the problem. Confirm the feasibility of the pro-
ject. Specify detailed requirements
2.3 ­Sample Databas 13

4) Logical Design – Delineate detailed functional specifications. Determine screen designs,


report layout designs, data models etc.
5) Physical Design – Develop physical data structures.
6) Implementation – Select DBMS. Convert data to conform to DBMS requirements. Code pro-
grams; perform testing.
7) Maintenance – Continue program modification until desired results are achieved.
An alternative approach to developing a database is through a phased process which will include
designing a conceptual model of the system that will imitate the real-world operation. It should be
flexible and change when the information in the database changes. Furthermore, it should not be
dependent upon the physical implementation. This process follows following phases:
1) Planning and Analysis – This phase is roughly equivalent to the first three steps men-
tioned above in the Systems Development Life Cycle. This includes requirement specifica-
tions, evaluating alternatives, and determining input, output, and reports to be generated.
2) Conceptual Design – Choose a data model and develop a conceptual schema based on the
requirement specification that was laid out in the planning and analysis phase. This conceptual
design focuses on how the data will be organized without having to worry about the specifics of
the tables, keys, and attributes. Identify the entities that will represent tables in the database,
identify attributes that will represent fields in a table, and identify each entity attribute relation-
ship. ER diagrams provide a good representation of the conceptual design.
3) Logical Design – Conceptual design is transformed into a logical design by creating a road-
map of how the database will look before actually creating the database. Data model is iden-
tified; usually, it is the relational model. Define the tables (entities) and fields (attributes).
Identify primary and foreign key for each table. Define relationships between the tables.
4) Physical Design – Develop physical data structures; specify file organization and data storage
etc. Take into consideration the availability of various resources including hardware and soft-
ware. This phase overlaps with the implementation phase. It involves the programming of the
database taking into account the limitations of the DBMS used.
5) Implementation – Choose the DBMS that will fulfill the user needs. Implement the physi-
cal design. Perform testing. Modify if necessary or until the database functions satisfactorily.

2.3 ­Sample Database

We will use a sample database CSE_DEPT to illustrate some essential database concepts.
Tables 2.1~2.5 show sample data tables stored in this database.
The data in CSE_DEPT database is stored in five tables – LogIn, Faculty, Course, Student, and
StudentCourse. A table consists of row and columns (Figure 2.1). A row represents a record, and
the column represents a field. Row is called a tuple, and a column is called an attribute. For exam-
ple, Student table has seven columns or fields – student_id, name, gpa, major, schoolYear, and
email. It has five records or rows.

2.3.1 Relational Data Model


Data model is like a blue print for developing a database. It describes the structure of the data-
base and various data relationships and constraints on the data. This information is used in
building tables, keys, and defining relationships. Relational model implies that a user perceives
Table 2.1 LogIn table.

user_name pass_word faculty_id student_id

abrown america B66750


ajade tryagain A97850
awoods smart A78835
banderson birthday A52990
bvalley see B92996
dangles tomorrow A77587
hsmith try H10210
terica excellent T77896
jhenry test H99118
jking goodman K69880
sbhalla india B86590
sjohnson jermany J33486
ybai come B78880

Table 2.2 Faculty table.

faculty_id faculty_ office phone college title email fimage


name

A52990 Black MTC-218 750-378-9987 Virginia Tech Professor banderson@ NULL


Anderson college.edu
A77587 Debby MTC-320 750-330-2276 University of Associate dangles@ NULL
Angles Chicago Professor college.edu
B66750 Alice MTC-257 750-330-6650 University of Assistant abrown@ NULL
Brown Florida Professor college.edu
B78880 Ying Bai MTC-211 750-378-1148 Florida Atlantic Associate ybai@college. NULL
University Professor edu
B86590 Davis MTC-214 750-378-1061 University of Associate dbhalla@ NULL
Bhalla Notre Dame Professor college.edu
H99118 Jeff Henry MTC-336 750-330-8650 Ohio State Associate jhenry@ NULL
University Professor college.edu
J33486 Steve MTC-118 750-330-1116 Harvard Distinguished sjohnson@ NULL
Johnson University Professor college.edu
K69880 Jenney MTC-324 750-378-1230 East Florida Professor jking@ NULL
King University college.edu

Table 2.3 Course table.

course_id course credit classroom schedule enrollment faculty_id

CSC-131A Computers in Society 3 TC-109 M-W-F: 9:00-9:55 28 A52990


AM
CSC-131B Computers in Society 3 TC-114 M-W-F: 9:00-9:55 20 B66750
AM
CSC-131C Computers in Society 3 TC-109 T-H: 11:00-12:25 PM 25 A52990
CSC-131D Computers in Society 3 TC-109 M-W-F: 9:00-9:55 AM 30 B86590
CSC-131E Computers in Society 3 TC-301 M-W-F: 1:00-1:55 PM 25 B66750
Table 2.3 (Continued)

course_id course credit classroom schedule enrollment faculty_id

CSC-131I Computers in Society 3 TC-109 T-H: 1:00-2:25 PM 32 A52990


CSC-132A Introduction to 3 TC-303 M-W-F: 9:00- 21 J33486
Programming 9:55 AM
CSC-132B Introduction to 3 TC-302 T-H: 1:00-2:25 PM 21 B78880
Programming
CSC-230 Algorithms & Structures 3 TC-301 M-W-F: 1:00-1:55 PM 20 A77587
CSC-232A Programming I 3 TC-305 T-H: 11:00-12:25 PM 28 B66750
CSC-232B Programming I 3 TC-303 T-H: 11:00-12:25 PM 17 A77587
CSC-233A Introduction to 3 TC-302 M-W-F: 9:00-9:55 18 H99118
Algorithms AM
CSC-233B Introduction to Algorithms 3 TC-302 M-W-F: 11:00- 19 K69880
11:55 AM
CSC-234A Data Structure & 3 TC-302 M-W-F: 9:00- 25 B78880
Algorithms 9:55 AM
CSC-234B Data Structure & 3 TC-114 T-H: 11:00-12:25 PM 15 J33486
Algorithms
CSC-242 Programming II 3 TC-303 T-H: 1:00-2:25 PM 18 A52990
CSC-320 Object Oriented 3 TC-301 T-H: 1:00-2:25 PM 22 B66750
Programming
CSC-331 Applications Programming 3 TC-109 T-H: 11:00-12:25 PM 28 H99118
CSC-333A Computer Arch & 3 TC-301 M-W-F: 10:00- 22 A77587
Algorithms 10:55 AM
CSC-333B Computer Arch & 3 TC-302 T-H: 11:00-12:25 PM 15 A77587
Algorithms
CSC-335 Internet Programming 3 TC-303 M-W-F: 1:00-1:55PM 25 B66750
CSC-432 Discrete Algorithms 3 TC-206 T-H: 11:00-12:25 PM 20 B86590
CSC-439 Database Systems 3 TC-206 M-W-F: 1:00-1:55 PM 18 B86590
CSE-138A Introduction to CSE 3 TC-301 T-H: 1:00-2:25 PM 15 A52990
CSE-138B Introduction to CSE 3 TC-109 T-H: 1:00-2:25 PM 35 J33486
CSE-330 Digital Logic Circuits 3 TC-305 M-W-F: 9:00- 26 K69880
9:55 AM
CSE-332 Foundations of 3 TC-305 T-H: 1:00-2:25 PM 24 K69880
Semiconductors
CSE-334 Elec. Measurement & 3 TC-212 T-H: 11:00-12:25 PM 25 H99118
Design
CSE-430 Bioinformatics in 3 TC-206 Thu: 9:30-11:00 AM 16 B86590
Computer
CSE-432 Analog Circuits Design 3 TC-309 M-W-F: 2:00-2:55 PM 18 K69880
CSE-433 Digital Signal Processing 3 TC-206 T-H: 2:00-3:25 PM 18 H99118
CSE-434 Advanced Electronics 3 TC-213 M-W-F: 1:00-1:55 PM 26 B78880
Systems
CSE-436 Automatic Control and 3 TC-305 M-W-F: 10:00-10:55 29 J33486
Design AM
CSE-437 Operating Systems 3 TC-303 T-H: 1:00-2:25 PM 17 A77587
CSE-438 Advd Logic & 3 TC-213 M-W-F: 11:00-11:55 35 B78880
Microprocessor AM
CSE-439 Special Topics in CSE 3 TC-206 M-W-F: 10:00- 22 J33486
10:55 AM
Table 2.4 Student table.

student_id student_name gpa credits major schoolYear email simage

A78835 Andrew Woods 3.26 108 Computer Science Senior awoods@college.edu NULL
A97850 Ashly Jade 3.57 116 Information System Junior ajade@college.edu NULL
Engineering
B92996 Blue Valley 3.52 102 Computer Science Senior bvalley@college.edu NULL
H10210 Holes Smith 3.87 78 Computer Sophomore hsmith@college.edu NULL
Engineering
T77896 Tom Erica 3.95 127 Computer Science Senior terica@college.edu NULL

Table 2.5 StudentCourse table.

s_course_id student_id course_id credit major

1000 H10210 CSC-131D 3 CE


1001 B92996 CSC-132A 3 CS/IS
1002 T77896 CSC-335 3 CS/IS
1003 A78835 CSC-331 3 CE
1004 H10210 CSC-234B 3 CE
1005 T77896 CSC-234A 3 CS/IS
1006 B92996 CSC-233A 3 CS/IS
1007 A78835 CSC-132A 3 CE
1008 A78835 CSE-432 3 CE
1009 A78835 CSE-434 3 CE
1010 T77896 CSC-439 3 CS/IS
1011 H10210 CSC-132A 3 CE
1012 H10210 CSC-331 2 CE
1013 A78835 CSC-335 3 CE
1014 A78835 CSE-438 3 CE
1015 T77896 CSC-432 3 CS/IS
1016 A97850 CSC-132B 3 ISE
1017 A97850 CSC-234A 3 ISE
1018 A97850 CSC-331 3 ISE
1019 A97850 CSC-335 3 ISE
1020 T77896 CSE-439 3 CS/IS
1021 B92996 CSC-230 3 CS/IS
1022 A78835 CSE-332 3 CE
1023 B92996 CSE-430 3 CE
1024 T77896 CSC-333A 3 CS/IS
1025 H10210 CSE-433 3 CE
1026 H10210 CSE-334 3 CE
1027 B92996 CSC-131C 3 CS/IS
1028 B92996 CSC-439 3 CS/IS
2.3 ­Sample Databas 17

Table

ID Name Ages Address Phone

1000 Tom 36 220 Ave 549-0507


Record 1002 Jim 58 101 Main 678-1002
2010 Jeff 49 25 Court 678-3211

3090 Kim 23 43 Route 202-5587

Field

Figure 2.1 Records and fields in a table.

the database as made up of relations, a database jargon for tables. It is imperative that all data
elements in the tables are represented correctly. In order to achieve these goals, designers use
various tools. The most commonly used tool is ER Model. A well-planned model will give con-
sistent results and will allow changes if needed later on. Following section further elaborates on
the ER Model.

2.3.2 Entity-Relationship (ER) Model


ER model was first proposed and developed by Peter Chen in 1976. Since then Charles Bachman
and James Martin have added some refinements, the model was designed to communicate the
database design in the form of a conceptual schema. The ER model is based on the perception that
the real world is made up of entities, their attributes, and relationships. The ER model is graphi-
cally depicted as ER diagrams (ERDs). ERDs are a major modeling tool; they graphically describe
the logical structure of the database. ER diagrams can be used with ease to construct the relational
tables and are a good vehicle for communicating the database design to the end user or a developer.
The three major components of ERD are entities, relationships, and the attributes.

2.3.2.1 Entities
An entity is a data object, either real or abstract, about which we want to collect information. For
example, we may want to collect information about a person, a place, or a thing. An entity in an ER
diagram translates into a table. It should preferably be referred to as an entity set. Some common
examples are departments, courses, and students. A single occurrence of an entity is an instance.
There are four entities in the CSE_Dept database, LogIn, Faculty, Course, and Student. Each entity
is translated into a table with the same name. An instance of the Faculty entity will be Alice Brown
and her attributes.

2.3.2.2 Relationships
A database is made up of related entities. There is a natural association between the entities; it is
referred to as relationship. For example,
●● Students take courses
●● Departments offer certain courses
●● Employees are assigned to departments
18 2 Introduction to Databases

The number of occurrences of one entity associated with single occurrence of a related entity is
referred to as cardinality.

2.3.2.3 Attributes
Each entity has properties or values called attributes associated with it. The attributes of an entity
map into fields in a table. Database Processing is one attribute of an entity called Courses. The
domain of an attribute is a set of all possible values from which an attribute can derive its value.

2.4 ­Identifying Keys

2.4.1 Primary Key and Entity Integrity


An attribute that uniquely identifies one and only one instance of an entity is called a primary key.
Sometimes a primary key consists of a combination of attributes. It is referred to as a composite key.
Entity integrity rule states that no attribute that is a member of the primary (composite) key may
accept a null value.
A faculty_id may serve as a primary key for the Faculty entity, assuming that all faculty mem-
bers have been assigned a unique FaultyID. However, caution must be exercised when picking an
attribute as a primary key. Last Name may not make a good primary key because a department is
likely to have more than one person with the same last name. Primary keys for the CSE_DEPT
database are shown in Table 2.6.
Primary keys provide a tuple level addressing mechanism in the relational databases. Once you
define an attribute as a primary key for an entity, the DBMS will enforce the uniqueness of the
primary key. Inserting a duplicate value for primary key field will fail.

Table 2.6 Faculty table.

faculty_id faculty_name title office phone college email fimage

A52990 Black Professor MTC-218 750-378- Virginia Tech banderson@ NULL


Anderson 9987 college.edu
A77587 Debby Angles Associate MTC-320 750-330- University of dangles@ NULL
Professor 2276 Chicago college.edu
B66750 Alice Brown Assistant MTC-257 750-330- University of abrown@ NULL
Professor 6650 Florida college.edu
B78880 Ying Bai Associate MTC-211 750-378- Florida ybai@college. NULL
Professor 1148 Atlantic edu
University
B86590 Davis Bhalla Associate MTC-214 750-378- University of dbhalla@ NULL
Professor 1061 Notre Dame college.edu
H99118 Jeff Henry Associate MTC-336 750-330- Ohio State jhenry@college. NULL
Professor 8650 University edu
J33486 Steve Johnson Distinguished MTC-118 750-330- Harvard sjohnson@ NULL
Professor 1116 University college.edu
K69880 Jenney King Professor MTC-324 750-378- East Florida jking@college. NULL
1230 University edu
2.5 ­Define Relationship 19

2.4.2 Candidate Key


There can be more than one attribute which uniquely identifies an instance of an entity. These are
referred to as candidate keys. Any one of them can serve as a primary key. For example, ID Number
as well as Social Security Number may make a suitable primary key. Candidate keys that are not
used as primary key are called alternate keys.

2.4.3 Foreign Keys and Referential Integrity


Foreign keys are used to create relationships between tables. It is an attribute in one table whose
values are required to match those of primary key in another table. Foreign keys are created to
enforce referential integrity which states that you may not add a record to a table containing a
foreign key unless there is a corresponding record in the related table to which it is logically linked.
Furthermore, the referential integrity rule also implies that every value of foreign key in a table
must match the primary key of a related table or be null. MS Access also makes provision for cas-
cade update and cascade delete which imply that changes made in one of the related tables will be
reflected in the other of the two related tables.
Consider two tables Course and Faculty in the sample database, CSE_DEPT. The Course table
has a foreign key entitled faculty_id which is the primary key in the Faculty table. The two tables
are logically related through the faculty_id link. Referential integrity rules imply that we may not
add a record to the Course table with a faculty_id which is not listed in the Faculty table. In other
words, there must be a logical link between the two related tables. Second, if we change or delete
a faculty_id in the Faculty table, it must reflect in the Course table meaning that all records in the
Course table must be modified using a cascade update or cascade delete (Tables 2.7).

2.5 ­Define Relationships

2.5.1 Connectivity
Connectivity refers to the types of relationships that entities can have. Basically, it can be one-
to-one, one-to-many, and many-to-many. In ER diagrams, these are indicated by placing 1, M or
N at one of the two ends of the relationship diagram. Figure illustrates the use of this
notation.

Table 2.7 Course (Partial data shown); Faculty (Partial data shown).

course_id course faculty_id faculty_id faculty_name office

CSC-132A Introduction to Programming J33486 A52990 Black Anderson MTC-218


CSC-132B Introduction to Programming B78880 A77587 Debby Angles MTC-320
CSC-230 Algorithms & Structures A77587 B66750 Alice Brown MTC-257
CSC-232A Programming I B66750 B78880 Ying Bai MTC-211
CSC-232B Programming I A77587 B86590 Davis Bhalla MTC-214
CSC-233A Introduction to Algorithms H99118 H99118 Jeff Henry MTC-336
CSC-233B Introduction to Algorithms K69880 J33486 Steve Johnson MTC-118
CSC-234A Data Structure & Algorithms B78880 K69880 Jenney King MTC-324
20 2 Introduction to Databases

●● A one-to-one (1 : 1) relationship occurs when one instance of entity A is related to only one
instance of entity B. For example, user_name in the LogIn table and user_name in the Student
table (Figure 2.2).
●● A one-to-many (1 : M) relationship occurs when one instance of entity A is associated with
zero, one, or many instances of entity B. However, entity B is associated with only one instance
of entity A. For example, one department can have many faculty members; each faculty member
is assigned to only one department. In CSE_DEPT database, One-to-many relationship is repre-
sented by faculty_id in the Faculty table and faculty_id in the Course table, student_id in the
Student table and student_id in the StudentCourse table, course_id in the Course table and
course_id in the StudentCourse table (Figure 2.3).
●● A many-to-many (M : N) relationship occurs when one instance of entity A is associated with
zero, one, or many instances of entity B. And one instance of entity B is associated with zero,
one, or many instance of entity A. For example, a student may take many courses, and one
course may be taken by more than one student (Figure 2.4).
In CSE_DEPT database, a many-to-many relationship can be realized by using the third table.
For example, in this case, the StudentCourse that works as the third table set a many-to-many
relationship between the Student and the Course tables.
This database design assumes that the course table only contains courses taught by all faculty
members in this department for one semester. Therefore, each course can only be taught by a
unique faculty. If one wants to develop a Course table that contains courses taught by all faculty in
more than one semester, the third table, say FacultyCourse table, should be created to set up a
many-to-many relationship between the Faculty and the Course table since one course may be
taught by the different faculty for the different semester.

LogIn Student
user_name pass_word user_name gpa credits student_id
ajade tryagain ajade 3.26 108 A97850
awoods smart awoods 3.57 116 A78835
bvalley see
bvalley 3.52 102 B92996
hsmith try
hsmith 3.87 78 H10210
terica excellent
terica 3.95 127 T77896

Figure 2.2 One-to-one relationship in the LogIn and the Student tables.

Faculty Course
faculty_id faculty_name office course_id course faculty_id
A52990 Black Anderson MTC-218 CSC-132A Introduction to Programming J33486
A77587 Debby Angles MTC-320 CSC-132B Introduction to Programming B78880
B66750 Alice Brown MTC-257 CSC-230 Algorithms & Structures A77587
B78880 Ying Bai MTC-211 CSC-232A Programming I B66750
B86590 Davis Bhalla MTC-214 CSC-232B Programming I A77587
H99118 Jeff Henry MTC-336 CSC-233A Introduction to Algorithms H99118
J33486 Steve Johnson MTC-118 CSC-233B Introduction to Algorithms K69880
K69880 Jenney King MTC-324 CSC-234A Data Structure & Algorithms B78880

Figure 2.3 One-to-many relationship between Faculty and Course tables.


2.5 ­Define Relationship 21

Course
Student
course_id course faculty_id
student_id student_name gpa credits
CSC-132A Introduction to Programming J33486
A78835 Andrew Woods 3.26 108
CSC-132B Introduction to Programming B78880
A97850 Ashly Jade 3.57 116
B92996 Blue Valley 3.52 102 CSC-230 Algorithms & Structures A77587

H10210 Holes Smith 3.87 78 CSC-232A Programming I B66750

T77896 Tom Erica 3.95 127 CSC-232B Programming I A77587


CSC-233A Introduction to Algorithms H99118

StudentCourse
s_course_id student_id course_id credit major
1000 H10210 CSC-131D 3 CE
1001 B92996 CSC-132A 3 CS/IS
1002 T77896 CSC-335 3 CS/IS
1003 A78835 CSC-331 3 CE
1004 H10210 CSC-234B 3 CE
1005 T77896 CSC-234A 3 CS/IS
1006 B92996 CSC-233A 3 CS/IS

Figure 2.4 Many-to-many relationship between Student and Course tables.

one-to-many
Login table Faculty table
P.K. F.K. F.K. P.K.
user_name pass_word faculty_id student_id faculty_id name office college

one-to-many one-to-many
Course table
Student table P.K. F.K.
P.K.
student_id name major gpa course_id course faculty_id credits

many-to-many

one-to-many StudentCourse table one-to-many


P.K. F.K. F.K.
s_course_id student_id course_id

Figure 2.5 Relationships in CSE_DEPT database.

The relationships in CSE_DEPT database are summarized in Figure 2.5.


Database name: CSE_DEPT
Five entities are:
●● LogIn
●● Faculty
22 2 Introduction to Databases

Figure 2.6 Relationships are illustrated using MS Access in the CSE_DEPT database. Source: Microsoft
Corporation.

●● Course
●● Student
●● StudentCourse
The relationships between these entities are shown below. P.K. and F.K represent the primary
key and the foreign key, respectively.
Figure 2.6 displays the Microsoft Access relationships diagram among various tables in the CSE_
Dept database. One-to-many relationship is indicated by placing 1 at one end of the link and at
the other. The many-to-many relationship between the Student and the Course table was broken
down to two one-to-many relationships by creating a new StudentCourse table.

2.6 ­ER Notation

There are a number of ER notations available including Chen’s, Bachman, Crow’s foot, and a few
others. There is no consensus on the symbols and the styles used to draw ERD’s. A number of
drawing tools are available to draw ERD’s. These include ER Assistant, Microsoft Visio, and Smart
Draw among others. Commonly used notations are shown in Figure 2.7.

2.7 ­Data Normalization

After identifying tables, attributes, and relationships, the next logical step in database design is to
make sure that the database structure is optimum. Optimum structure is achieved by eliminating
redundancies, various inefficiencies, and update and deletion anomalies that usually occur in the
2.7 ­Data Normalizatio 23

Entity is represented by a
rectangular box.

A weak entity is represented


by a double rectangular box.

An attribute is represented by
an oval

Relationship is represented
by a diamond with lines
connecting the entities
involved

Cardinality is indicated by 1 M
placing 1, N, or M near the
entity it is associated with

A line links entities to


attributes and
relationships

Figure 2.7 Commonly used symbols for ER notation.

unnormalized or partially normalized databases. Data normalization is a progressive process. The


steps in the normalization process are called normal forms. Each normal form progressively
improves the database and makes it more efficient. In other words, a database that is in second
normal form (2NF) is better than the one in the first normal form (1NF), and the one in third nor-
mal form (3NF) is better than the one in 2NF. To be in the 3NF, a database has to be in the 1NF and
2NF. There are fourth and fifth normal forms but for most practical purposes, a database meeting
the criteria of third normal form is considered to be of good design.

2.7.1 First Normal Form (1NF)


A table is in 1NF if values in each column are atomic, that is there are no repeating groups of data.
The following Faculty table (Table 2.8) is not normalized. Some faculty members have more than
one telephone number listed in the phone column. These are called repeating groups.
In order to convert this table to the INF, the data must be atomic. In other words, the repeating
rows must be broken into two or more atomic rows. Table 2.9 illustrates the Faculty table in 1NF
where repeating groups have been removed. Now, it is in 1NF.

2.7.2 Second Normal Form (2NF)


A table is in 2NF if it is already in 1NF and every non-key column is fully dependent upon the
primary key.
24 2 Introduction to Databases

Table 2.8 Unnormalized Faculty table with repeating groups.

faculty_id faculty_name office phone

A52990 Black Anderson MTC-218, SHB-205 750-378-9987, 555-255-8897


A77587 Debby Angles MTC-320 750-330-2276
B66750 Alice Brown MTC-257 750-330-6650
B78880 Ying Bai MTC-211, SHB-105 750-378-1148, 555-246-4582
B86590 Davis Bhalla MTC-214 750-378-1061
H99118 Jeff Henry MTC-336 750-330-8650
J33486 Steve Johnson MTC-118 750-330-1116
K69880 Jenney King MTC-324 750-378-1230

Table 2.9 Normalized Faculty table.

faculty_id faculty_name office phone

A52990 Black Anderson MTC-218 750-378-9987


A52990 Black Anderson SHB-205 555-255-8897
A77587 Debby Angles MTC-320 750-330-2276
B66750 Alice Brown MTC-257 750-330-6650
B78880 Ying Bai MTC-211 750-378-1148
B78880 Ying Bai SHB-105 555-246-4582
B86590 Davis Bhalla MTC-214 750-378-1061
H99118 Jeff Henry MTC-336 750-330-8650
J33486 Steve Johnson MTC-118 750-330-1116
K69880 Jenney King MTC-324 750-378-1230

This implies that if the primary key consists of a single column, then the table in 1NF is auto-
matically in 2NF. The second part of the definition implies that if the key is composite, then none
of the non-key columns will depend upon just one of the columns that participates in the com-
posite key.
The Faculty table in Table 2.9 is in 1NF. However, it has a composite primary key, made up of
faculty_id and office. The phone number depends on a part of the primary key, the office and not
on the whole primary key. This can lead to update and deletion anomalies mentioned above.
By splitting the old Faculty table (Figure 2.8) into two new tables, Faculty and Office, we can
remove the dependencies mentioned earlier. Now, the faculty table has a primary key, faculty_id,
and the Office table has a primary key, office. The non-key columns in both tables now depend
only on the primary keys only.

2.7.3 Third Normal Form (3NF)


A table is in 3NF if it is already in 2NF and every non-key column is non-transitively dependent
upon the primary key. In other words, all non-key columns are mutually independent, but at the
same time, they are fully dependent upon the primary key only.
2.8 ­Database Components in Some Popular Database 25

Old Faculty table in 1NF


faculty_id faculty_name office phone
A52990 Black Anderson MTC-218 750-378-9987
A52990 Black Anderson SHB-205 555-255-8897
A77587 Debby Angles MTC-320 750-330-2276
B66750 Alice Brown MTC-257 750-330-6650
B78880 Ying Bai MTC-211 750-378-1148
B78880 Ying Bai SHB-105 555-246-4582
B86590 Davis Bhalla MTC-214 750-378-1061
H99118 Jeff Henry MTC-336 750-330-8650
J33486 Steve Johnson MTC-118 750-330-1116
K69880 Jenney King MTC-324 2750-378-1230

New Faculty table New Office table


faculty_id faculty_name office phone faculty_id
A52990 Black Anderson MTC-218 750-378-9987 A52990
A52990 Black Anderson SHB-205 555-255-8897 A52990
A77587 Debby Angles MTC-320 750-330-2276 A77587
B66750 Alice Brown MTC-257 750-330-6650 B66750
B78880 Ying Bai MTC-211 750-378-1148 B78880
B78880 Ying Bai SHB-105 555-246-4582 B78880
B86590 Davis Bhalla MTC-214 750-378-1061 B86590
H99118 Jeff Henry MTC-336 750-330-8650 H99118
J33486 Steve Johnson MTC-118 750-330-1116 J33486
K69880 Jenney King MTC-324 750-378-1230 K69880

Figure 2.8 Converting Faculty table into 2NF by decomposing the old table in two, Faculty and Office.

Another way of stating this is that in order to achieve 3NF, no column should depend upon any
non-key column. If column B depends on column A, then A is said to functionally determine col-
umn B, hence the term determinant. Another definition of 3NF says that the table should be in
2NF and only determinants it contains are candidate keys.
For the Course table in Table 2.10, all non-key columns depend on the primary key – course_id. In
addition, name and phone columns also depend on faculty_id. This table is in 2NF but it suffers from
update, addition, and deletion anomalies because of transitive dependencies. In order to conform to
3NF, we can split this table into two tables, Course and Instructor (Tables 2.11 and 2.12). Now, we
have eliminated the transitive dependencies that are apparent in the Course table in Table 2.10.

2.8 ­Database Components in Some Popular Databases

All databases allow for storage, retrieval, and management of the data. Simple databases provide
basic services to accomplish these tasks. Many database providers, like Microsoft SQL Server and
Oracle, provide additional services which necessitates storing many components in the database
other than data. These components such as views, stored procedures etc., are collectively called
Another random document with
no related content on Scribd:
the furniture had not been changed—she was astonished, and
curiously agitated, at setting out from the very same house for the
very same Opera box. The only difference would be in the mode of
progression; she remembered the Parisian landau and sixteen-hand
chestnuts with glittering plated harness that had waited at the door in
her early married days. Then she had a vision of her own toilet, of
the elaborate business it used to be: Aline’s predecessor, with
cunning fingers, dividing and coiling the generous ripples of her hair,
and building nests of curls about the temples and in the nape; then
the dash up in her dressing-gown to Anne’s nursery for a last kiss,
and the hurrying back to get into her splendid brocade, to fasten the
diamond coronet, the ruby “sunburst”, the triple pearls. John
Clephane was fond of jewels, and particularly proud of his wife’s, first
because he had chosen them, and secondly because he had given
them to her. She sometimes thought he really admired her only when
she had them all on, and she often reflected ironically on Esther’s
wifely guile in donning her regal finery before she ventured to
importune Ahasuerus. It certainly increased Kate Clephane’s
importance in her husband’s eyes to know that, when she entered
her box, no pearls could hold their own against hers except Mrs.
Beaufort’s and old Mrs. Goldmere’s.
It was years since Kate Clephane had thought of those jewels. She
smiled at the memory, and at the contrast between the unobtrusive
dress Aline had just prepared for her, and all those earlier
splendours. The jewels, she supposed, were Anne’s now; since
modern young girls dressed as richly as their elders, Anne had no
doubt had them reset for her own use. Mrs. Clephane closed her
eyes with a smile of pleasure, picturing Anne (as she had not yet
seen her) with bare arms and shoulders, and the orient of the pearls
merging in that of her young skin. It was lucky that Anne was tall
enough to look her best in jewels. Thence the mother’s fancy
wandered to the effect Anne must produce on other imaginations; on
those, particularly, of young men. Was she already, as they used to
say, “interested”? Among the young men Mrs. Clephane had seen,
either calling at the house, or in the course of informal dinners at the
Tresseltons’, the Drovers’, and other cousins or “in-laws”, she had
remarked none who seemed to fix her daughter’s attention. But there
had been, as yet, few opportunities: the mitigated mourning for old
Mrs. Clephane did at least seclude them from general society, and
when a girl as aloof as Anne was attracted, the law of contrasts
might draw her to some one unfamiliar and undulled by propinquity.
“Or an older man, perhaps?” Kate considered. She thought of Anne’s
half-daughterly, half-feminine ways with her former guardian, and
then shrugged away the possibility that her old stolid Fred could
exercise a sentimental charm. Yet the young men of Anne’s
generation, those her mother had hitherto met, seemed curiously
undifferentiated and immature, as if they had been kept too long in
some pure and enlightened school, eternally preparing for a life into
which their parents and professors could never decide to let them
plunge.... It struck Mrs. Clephane that Chris, when she first met him,
must have been about the age of these beautiful inarticulate athletes
... and Heaven knew how many lives he had already run through! As
he said himself, he felt every morning when he woke as if he had
come into a new fortune, and had somehow got to “blow it all in”
before night.
Kate Clephane sat up and brushed her hand over her eyes. It was
the first time Chris had been present to her, in that insistent
immediate way, since her return to New York. She had thought of
him, of course—how could she cast even a glance over her own past
without seeing him there, woven into its very texture? But he seemed
to have receded to the plane of that past: from his torturing actual
presence her new life had delivered her.... She pressed both hands
against her eyes, as if to crush and disperse the image stealthily
forming; then she rose and went into her bedroom, where, a moment
before, she had heard Aline laying out her dress.
The maid had finished and gone; the bedroom was empty. The
change of scene, the mere passage from one room to another, the
sight of the evening dress and opera-cloak on the bed, and of
Beatrice Cenci looking down on them through her perpetual sniffle,
sufficed to recall Kate to the present. She turned to the dressing-
table, and noticed a box which had been placed before her mirror. It
was of ebony and citron-wood, embossed with agates and
cornelians, and heavily clasped with chiselled silver; and from the
summit of the lid a silver Cupid bent his shaft at her.
Kate broke into a faint laugh. How well she remembered that box!
She did not have to lift the lid to see its padded trays and tufted sky-
blue satin lining! It was old Mrs. Clephane’s jewel-box, and on Kate’s
marriage the dowager had solemnly handed it over to her daughter-
in-law with all that it contained.
“I wonder where Anne found it?” Kate conjectured, amused by the
sight of one more odd survival in that museum of the past which
John Clephane’s house had become. A little key hung on one of the
handles, and she put it in the lock, and saw all her jewels lying
before her. On a slip of paper Anne had written: “Darling, these
belong to you. Please wear some of them tonight....”

As she entered the opera box Kate Clephane felt as if the great
central chandelier were raying all its shafts upon her, as if she were
somehow caught up into and bound on the wheel of its devouring
blaze. But only for a moment—after that it seemed perfectly natural
to be sitting there with her daughter and Nollie Tresselton, backed by
the usual cluster of white waistcoats. After all, in this new existence it
was Anne who mattered, not Anne’s mother; instantly, after the first
plunge, Mrs. Clephane felt herself merged in the blessed anonymity
of motherhood. She had never before understood how exposed and
defenceless her poor unsupported personality had been through all
the lonely years. Her eyes rested on Anne with a new tenderness;
the glance crossed Nollie Tresselton’s, and the two triumphed in their
shared admiration. “Oh, there’s no one like Anne,” their four eyes
told each other.
Anne looked round and intercepted the exchange. Her eyes smiled
too, and turned with a childish pleasure to the pearls hanging down
over her mother’s black dress.
“Isn’t she beautiful, Nollie?”
Young Mrs. Tresselton laughed. “You two were made for each other,”
she said.
Mrs. Clephane closed her lids for an instant; she wanted to drop a
curtain between herself and the stir and brightness, and to keep in
her eyes the look of Anne’s as they fell on the pearls. The episode of
the jewels had moved the mother strangely. It had brought Anne
closer than a hundred confidences or endearments. As Kate sat
there in the dark, she saw, detached against the blackness of her
closed lids, a child stumbling with unsteady steps across a windy
beach, a funny flushed child with sand in her hair and in the creases
of her fat legs, who clutched to her breast something she was
bringing to her mother. “It’s for mummy,” she said solemnly, opening
her pink palms on a dead star-fish. Kate saw again the child’s
rapturous look, and felt the throb of catching her up, star-fish and all,
and devouring with kisses the rosy body and tousled head.
In themselves the jewels were nothing. If Anne had handed her a bit
of coal—or another dead star-fish—with that look and that intention,
the gift would have seemed as priceless. Probably it would have
been impossible to convey to Anne how indifferent her mother had
grown to the Clephane jewels. In her other life—that confused
intermediate life which now seemed so much more remote than the
day when the little girl had given her the star-fish—jewels, she
supposed, might have pleased her, as pretty clothes had, or flowers,
or anything that flattered the eye. Yet she could never remember
having regretted John Clephane’s jewels; and now they would have
filled her with disgust, with abhorrence almost, had they not, in the
interval, become Anne’s.... It was the girl who gave them their
beauty, made them exquisite to the mother’s sight and touch, as
though they had been a part of her daughter’s loveliness, the
expression of something she could not speak.
Mrs. Clephane suddenly exclaimed to herself: “I am rewarded!” It
was a queer, almost blasphemous, fancy—but it came to her so. She
was rewarded for having given up her daughter; if she had not, could
she ever have known such a moment as this? She had been too
careless and impetuous in her own youth to be worthy to form and
guide this rare creature; and while she seemed to be rushing blindly
to her destruction, Providence had saved the best part of her in
saving Anne. All these scrupulous self-controlled people—Enid and
Hendrik Drover, Fred Landers, even the arch enemy, old Mrs.
Clephane—had taken up the task she had flung aside, and carried it
out as she could never have done. And she had somehow run the
mad course allotted to her, and come out of it sane and sound, to
find them all waiting there to give her back her daughter. It was
incredible, but there it was. She bowed her head in self-abasement.
The box door was opening and shutting softly, on the stage voices
and instruments soared and fell. She did not know how long she sat
there in a kind of brooding rapture. But presently she was roused by
hearing a different voice at her elbow. She half opened her eyes, and
saw a newcomer sitting by Anne. It was one of the young men who
came to the house; his fresh blunt face was as inexpressive as a
football; he might have been made by a manufacturer of sporting-
goods.
“—in the box over there; but he’s gone now; bolted. Said he was too
shy to come over and speak to you. Give you my word, he’s got it
bad; we couldn’t get him off the subject.”
“Shy?” Anne murmured ironically.
“That’s what he said. Said he’s never had the microbe before.
Anyhow, he’s bolted off home. Says he don’t know when he’ll come
back to New York.”
Kate Clephane, watching her daughter through narrowed lids,
perceived a subtle change in her face. Anne did not blush—that
close-textured skin of hers seldom revealed the motions of her
blood. Her delicate profile remained shut, immovable; she merely
lowered her lids as if to keep in a vision. It was Kate’s own gesture,
and the mother recognized it with a start. She had been right, then;
there was some one—some one whom Anne had to close her eyes
to see! But who was he? Why had he been too shy to come to the
box? Where did he come from, and whither had he fled?
Kate glanced at Nollie Tresselton, wondering if she had overheard;
but Nollie, in the far corner of the box, leaned forward, deep in the
music. Joe Tresselton had vanished, Landers slumbered in the rear.
With a little tremor of satisfaction, Kate saw that she had her
daughter’s secret to herself: if there was no one to enlighten her
about it at least there was no one to share it with her, and she was
glad. For the first time she felt a little nearer to Anne than all the
others.
“It’s odd,” she thought, “I always knew it would be some one from a
distance.” But there are no real distances nowadays, and she
reflected with an inward smile that the fugitive would doubtless soon
reappear, and her curiosity be satisfied.
That evening, when Anne followed her into her bedroom, Mrs.
Clephane opened the wardrobe in which she had placed the jewel-
box. “Here, my dear; you shall choose one thing for me to wear. But I
want you to take back all the rest.”
The girl’s face clouded. “You won’t keep them, then? But they’re all
yours!”
“Even if they were, I shouldn’t want them any longer. But they’re not,
they’re only a trust—” she paused, half smiling—“a trust till your
wedding.”
She had tried to say the word lightly, but it echoed on through the
silence like a peal of silver bells.
“Oh, my wedding! But I shall never marry,” said Anne, laughing
joyously, and catching her mother in her arms. It was the first time
she had made so impulsive a movement; Kate Clephane, trembling
a little, held her close.
It brought the girl nearer, made her less aloof, to hear that familiar
old denial. “Some day before long,” the mother thought, “she’ll tell
me who he is.”
VI.
KATE CLEPHANE lay awake all night thinking of the man who had
been too shy to come into the box.
Her sense of security, of permanence, was gone. She understood
now that it had been based on the idea that her life would henceforth
go on just as it had for the two months since her return; that she and
Anne would always remain side by side. The idea was absurd, of
course; if she followed it up, her mind recoiled from it. To keep Anne
for the rest of her life unchanged, and undesirous of change—the
aspiration was inconceivable. She wanted for her daughter the
common human round, no more, but certainly no less. Only she did
not want her to marry yet—not till they two had grown to know each
other better, till Kate had had time to establish herself in her new life.
So she put it to herself; but she knew that what she felt was just an
abject fear of change, more change—of being uprooted again, cast
once more upon her own resources.
No! She could not picture herself living alone in a little house in New
York, dependent on Drovers and Tresseltons, and on the good Fred
Landers, for her moral sustenance. To be with Anne, to play the part
of Anne’s mother—the one part, she now saw, that fate had meant
her for—that was what she wanted with all her starved and world-
worn soul. To be the background, the atmosphere, of her daughter’s
life; to depend on Anne, to feel that Anne depended on her; it was
the one perfect companionship she had ever known, the only close
tie unmarred by dissimulation and distrust. The mere restfulness of it
had made her contracted soul expand as if it were sinking into a
deep warm bath.
Now the sense of restfulness was gone. From the moment when she
had seen Anne’s lids drop on that secret vision, the mother had
known that her days of quietude were over. Anne’s choice might be
perfect; she, Kate Clephane, might live out the rest of her days in
peace between Anne and Anne’s husband. But the mere possibility
of a husband made everything incalculable again.
The morning brought better counsel. There was Anne herself, in her
riding-habit, aglow from an early canter, and bringing in her mother’s
breakfast, without a trace of mystery in her clear eyes. There was
the day’s pleasant routine, easy and insidious, the planning and
adjusting of engagements, notes to be answered, invitations to be
sent out; the habitual took Mrs. Clephane into its soothing hold.
“After all,” she reflected, “young men don’t run away nowadays from
falling in love.” Probably the whole thing had been some cryptic chaff
of the youth with the football face; Nollie, indirectly, might enlighten
her.
Indirectly; for it was clear to Kate that whatever she learned about
her daughter must be learned through observing her, and not
through questioning others. The mother could not picture herself as
having any rights over the girl, as being, under that roof, anything
more than a privileged guest. Anne’s very insistence on treating her
as the mistress of the house only emphasized her sense of not being
so by right: it was the verbal courtesy of the Spaniard who puts all
his possessions at the disposal of a casual visitor.
Not that there was anything in Anne’s manner to suggest this; but
that to Kate it seemed inherent in the situation. It was absurd to
assume that her mere return to John Clephane’s house could invest
her, in any one else’s eyes, and much less in her own, with the
authority she had lost in leaving it; she would never have dreamed of
behaving as if she thought so. Her task, she knew, was gradually,
patiently, to win back, of all she had forfeited, the one thing she really
valued: her daughter’s love and confidence. The love, in a measure,
was hers already; could the confidence fail to follow?
Meanwhile, at any rate, she could be no more than the fondest of
lookers-on, the discreetest of listeners; and for the moment she
neither saw nor heard anything to explain that secret tremor of
Anne’s eyelids.
At the Joe Tresseltons’, a few nights later, she had hoped for a
glimpse, a hint. Nollie had invited mother and daughter (with
affectionate insistence on the mother’s presence) to a little evening
party at which some one who was not Russian was to sing—for
Nollie was original in everything. The Joe Tresseltons had managed
to lend a freshly picturesque air to a dull old Tresselton house near
Washington Square, of which the stable had become a studio, and
other apartments suffered like transformations, without too much
loss of character. It was typical of Nollie that she could give an
appearance of stability to her modern furnishings, just as her modern
manner kept its repose.
The party was easy and amusing, but even Lilla Gates (whom Nollie
always included) took her tone from the mistress of the house, and,
dressed with a kind of savage soberness, sat there in her heavy
lustreless beauty, bored but triumphant. It was evident that, though
at Nollie’s she was not in her element, she would not for the world
have been left out.
Kate Clephane, while the music immobilized the groups scattered
about the great shadowy room, found herself scanning them with a
fresh intensity of attention. She no longer thought of herself as an
object of curiosity to any of these careless self-engrossed young
people; she had learned that a woman of her age, however
conspicuous her past, and whatever her present claims to notice, is
fated to pass unremarked in a society where youth so undisputedly
rules. The discovery had come with a slight shock; then she blessed
the anonymity which made observation so much easier.
Only—what was there to observe? Again the sameness of the
American Face encompassed her with its innocent uniformity. How
many of them it seemed to take to make up a single individuality!
Most of them were like the miles and miles between two railway
stations. She saw again, with gathering wonder, that one may be
young and handsome and healthy and eager, and yet unable, out of
such rich elements, to evolve a personality.
Her thoughts wandered back to the shabby faces peopling her
former life. She knew every seam of their shabbiness, but now for
the first time she seemed to see that they had been worn down by
emotions and passions, however selfish, however sordid, and not
merely by ice-water and dyspepsia.
“Since the Americans have ceased to have dyspepsia,” she
reflected, “they have lost the only thing that gave them any
expression.”
Landers came up as the thought flashed through her mind, and
apparently caught its reflection in her smile.
“You look at me as if you’d never seen me before; is it because my
tie’s crooked?” he asked, sitting down beside her.
“No; your tie is absolutely straight. So is everything else about you.
That’s the reason I was looking at you in that way. I can’t get used to
it!”
He reddened a little, as if unaccustomed to such insistent scrutiny.
“Used to what?”
“The universal straightness. You’re all so young and—and so
regular! I feel as if I were in a gallery of marble masterpieces.”
“As that can hardly apply to our features, I suppose it’s intended to
describe our morals,” he said with a faint grimace.
“I don’t know—I wish I did! What I’m trying to do, of course,” she
added abruptly and unguardedly, “is to guess how I should feel about
all these young men—if I were Anne.”
She was vexed with herself that the words should have slipped out,
and yet not altogether sorry. After all, one could always trust Landers
to hold his tongue—and almost always to understand. His smile
showed that he understood now.
“Of course you’re trying; we all are. But, as far as I know, Sister Anne
hasn’t yet seen any one from her tower.”
A breath of relief expanded the mother’s heart.
“Ah, well, you’d be sure to know—especially as, when she does, it
ought to be some one visible a long way off!”
“It ought to be, yes. The more so as she seems to be in no hurry.” He
looked away. “But don’t build too much on that,” he added. “I learned
long ago, in such matters, to expect only the unexpected.”
Kate Clephane glanced at him quickly; his ingenuous countenance
wore an unaccustomed shadow. She remembered that, in old days,
John Clephane had always jokingly declared—in a tone proclaiming
the matter to be one mentionable only as a joke—that Fred Landers
was in love with her; and she said to herself that the lesson her old
friend referred to was perhaps the one she had unwittingly given him
when she went away with another man.
It was on the tip of her tongue to exclaim: “Oh, but I didn’t know
anything then—I wasn’t anybody! My real life, my only life, began
years later—” but she checked herself with a start. Why, in the very
act of thinking of her daughter, had she suddenly strayed away into
thinking of Chris? It was the first time it had happened to her to
confront the two images, and she felt as if she had committed a sort
of profanation.
She took refuge in another thought that Landers’s last words had
suggested—the thought that if she herself had matured late, why so
might Anne. The idea was faintly reassuring.
“No; I won’t build on any theory,” she said, answering him. “But one
can’t help hoping she’ll wait till some one turns up good enough for
what she’s going to be.”
“Oh, these mothers!” he laughed, his face smoothing out into its
usual guileless lines.
The music was over. The groups flowed past them toward the little
tables in another picturesque room, and Lilla Gates swept by in a
cluster of guffawing youths. She seemed to have attracted all the
kindred spirits in the room, and her sluggish stare was shot with
provocation. Ah, there was another mystery! No one explained Lilla
—every one seemed to take her for granted. Not that it really
mattered; Kate had seen enough of Anne to feel sure she would
never be in danger of falling under Lilla’s influence. The perils in wait
for her would wear a subtler form. But, as a matter of curiosity, and a
possible light on the new America, Kate would have liked to know
why her husband’s niece—surprising offshoot of the prudent
Clephanes and stolid Drovers—had been singled out, in this new
easy-going society, to be at once reproved and countenanced. Lilla
in herself was too uninteresting to stimulate curiosity; but as a
symptom she might prove enlightening. Only, here again, Kate had
the sense that she, of all the world, was least in a position to ask
questions. What if people should turn around and ask them about
her? Since she had been living under her old roof, and at her
daughter’s side, the mere suggestion made her tremble. It was
curious—and she herself was aware of it—how quickly,
unconsciously almost, she had slipped at last into the very attitude
the Clephanes had so long tried to force upon her: the attitude of
caution and conservatism.
Her glance, in following Lilla, caught Fred Landers’s, and he smiled
again, but with a slight constraint. Instantly she thought: “He’d like to
tell me her whole story, but he doesn’t dare, because very likely it
began like my own. And it will always go on being like that: whatever
I’m afraid to ask they’ll be equally afraid to tell.” Well, that was what
people called “starting with a clean slate”, she supposed; would no
one ever again scribble anything unguardedly on hers? She felt
indescribably alone.
On the way home the mere feeling of Anne’s arm against hers drew
her out of her solitariness. After all, she had only to wait. The new life
was but a few weeks old; and already Anne’s nearness seemed to fill
it. If only she could keep Anne near enough!
“Did you like it, mother? How do we all strike you, I wonder?” the girl
asked suddenly.
“As kinder than anything I ever dreamed.”
She thought she felt Anne’s surprised glance in the darkness. “Oh,
that! But why not? It’s you who must try to be kind to us. I feel as if
we must be so hard to tell apart. In Europe there are more contrasts,
I suppose. I saw Uncle Fred helping you to sort us out this evening.”
“You mean you caught me staring? I daresay I do. I want so much
not to miss anything ... anything that’s a part of your life....” Her voice
shook with the avowal.
She was answered by a closer pressure. “You wonderful mother! I
don’t believe you ever will.” She was conscious in Anne,
mysteriously, of a tension answering her own. “Isn’t it splendid to be
two to talk things over?” the girl said joyously.
“What things?” Kate Clephane thought; but dared not speak. Her
hand on Anne’s, she sat silent, feeling her child’s heart tremble
nearer.
VII.
EVERY one noticed how beautifully it worked; the way, as Fred
Landers said, she and Anne had hit it off from their first look at each
other on the deck of the steamer.
Enid Drover was almost emotional about it, one evening when she
and Kate sat alone in the Clephane drawing-room. It was after one of
Anne’s “young” dinners, and the other guests, with Anne herself, had
been whirled off to some form of midnight entertainment.
“It’s wonderful, my dear, how you’ve done it. Poor mother didn’t
always find Anne easy, you know. But she’s taken a tremendous
fancy to you.”
Kate felt herself redden with pride. “I suppose it’s the novelty, partly,”
Mrs. Drover continued, with her heavy-stepping simplicity. “Perhaps
that’s an advantage, in a way.” But she pulled up, apparently feeling
that, in some obscure manner, she might be offending where she
sought to please. “Anne admires your looks so much, you know; and
your slightness.” A sigh came from her adipose depths. “I do believe
it gives one more hold over one’s girls to have kept one’s figure. One
can at least go on wearing the kind of clothes they like.”
Kate felt an inward glow of satisfaction. The irony of the situation
hardly touched her: the fact that the youth and elasticity she had
clung to so desperately should prove one of the chief assets of her
new venture. It was beginning to seem natural that everything should
lead up to Anne.
“This business of setting up a studio, now; Anne’s so pleased that
you approve. She had a struggle with her grandmother about it; but
poor mother wouldn’t give in. She was too horrified. She thought
paint so messy—and then how could she have got up all those
stairs?”
“Ah, well”—it was so easy to be generous!—“that sort of thing did
seem horrifying to Mrs. Clephane’s generation. After all, it was not so
long before her day that Dr. Johnson said portrait-painting was
indelicate in a female.”
Mrs. Drover gave her sister-in-law a puzzled look. Her mind seldom
retained more than one word in any sentence, and her answer was
based on the reaction that particular word provoked. “Female—” she
murmured—“is that word being used again? I never thought it very
nice to apply it to women, did you? I suppose I’m old-fashioned.
Nothing shocks the young people nowadays—not even the Bible.”
Nothing could have given Kate Clephane greater confidence in her
own success than this little talk with Enid Drover. She had been
feeling her way so patiently, so stealthily almost, among the out-
works and defences of her daughter’s character; and here she was
actually instated in the citadel.
Anne’s “studio-warming” strengthened the conviction. Mrs. Clephane
had not been allowed to see the studio; Anne and Nollie and Joe
Tresselton, for a breathless week, had locked themselves in with
nails and hammers and pots of paint, sealing their ears against all
questioning. Then one afternoon the doors were opened, and Kate,
coming out of the winter twilight, found herself in a great half-lit room
with a single wide window overlooking the reaches of the Sound all
jewelled and netted with lights, the fairy span of the Brooklyn Bridge,
and the dark roof-forest of the intervening city. It all seemed
strangely significant and mysterious in that disguising dusk—full of
shadows, distances, invitations. Kate leaned in the window,
surprised at this brush of the wings of poetry.
In the room, Anne had had the good taste to let the sense of space
prolong itself. It looked more like a great library waiting for its books
than a modern studio; as though the girl had measured the distance
between that mighty nocturne and her own timid attempts, and
wanted the implements of her art to pass unnoticed.
They were sitting—Mrs. Clephane, the Joe Tresseltons and one or
two others—about the tea-cups set out at one end of a long oak
table, when the door opened and Lilla Gates appeared, tawny and
staring, in white furs and big pendulous earrings. She brought with
her a mingled smell of cigarettes and Houbigant, and as she stood
there, circling the room with her sulky contemptuous gaze, Kate felt
a movement of annoyance.
“Why must one forever go on being sorry for Lilla?” she wondered,
wincing a little as Anne’s lips touched her cousin’s mauve cheek.
“It was nice of you to come, Lilla.”
“Well—I chucked something bang-up for you,” said Lilla coolly. It was
evidently her pride to be perpetually invited, perpetually swamped in
a multiplicity of boring engagements. She looked about her again,
and then dropped into an armchair. “Mercy—you have cleared the
decks!” she remarked. “Ain’t there going to be any more furniture
than this?”
“Oh, the furniture’s all outside—and the pictures too,” Anne said,
pointing to the great window.
“What—Brooklyn Bridge? Lord!—Oh, but I see: you’ve kept the place
clear for dancing. Good girl, Anne! Can I bring in some of my little
boys sometimes? Is that a pianola?” she added, with a pounce
toward the grand piano in a shadowy corner. “I like this
kindergarten,” she pronounced.
Nollie Tresselton laughed. “If you come, Anne won’t let you dance.
You’ll all have to sit for her—for hours and hours.”
“Well, we’ll sit between the dances then. Ain’t I going to have a latch-
key, Anne?”
She stood leaning against the piano, sipping the cock-tail some one
had handed her, her head thrown back, and the light from a shaded
lamp striking up at her columnar throat and the green glitter of her
earrings, which suggested to Kate Clephane the poisonous antennæ
of some giant insect. Anne stood close to her, slender, erect, her
small head clasped in close braids, her hands hanging at her sides,
dead-white against the straight dark folds of her dress. There was
something distinctly unpleasant to Kate Clephane in the proximity of
the two, and she rose and moved toward the piano.
As she sat down before it, letting her hands drift into the opening
bars of a half-remembered melody, she saw Lilla, in her vague
lounging way, draw nearer to Anne, who held out a hand for the
empty cock-tail glass. The gesture brought them so close that Lilla,
slightly drooping her head, could let fall, hardly above her breath, but
audibly to Kate: “He’s back again. He bothered the life out of me to
bring him here today.”
Again Kate saw that quick drop of her daughter’s lids; this time it was
accompanied by a just-perceptible tremor of the hand that received
the glass.
“Nonsense, Lilla!”
“Well, what on earth am I to do about it? I can’t get the police to run
him in, can I?”
Anne laughed—the faintest half-pleased laugh of impatience and
dismissal. “You may have to,” she said.
Nollie Tresselton, in the interval, had glided up and slipped an arm
through Lilla’s.
“Come along, my dear. There’s to be no dancing here today.” Her
little brown face had the worn sharp look it often took on when she
was mothering Lilla. But Lilla’s feet were firmly planted. “I don’t
budge till I get another cock-tail.”
One of the young men hastened to supply her, and Anne turned to
her other guests. A few minutes later the Tresseltons and Lilla went
away, and one by one the remaining visitors followed, leaving mother
and daughter alone in the recovered serenity of the empty room.
But there was no serenity in Kate. That half-whispered exchange
between Lilla Gates and Anne had stirred all her old apprehensions
and awakened new ones. The idea that her daughter was one of
Lilla’s confidants was inexpressibly disturbing. Yet the more she
considered, the less she knew how to convey her anxiety to her
daughter.
“If I only knew how intimate they really are—what she really thinks of
Lilla!”
For the first time she understood on what unknown foundations her
fellowship with Anne was built. Were they solid? Would they hold?
Was Anne’s feeling for her more than a sudden girlish enthusiasm for
an agreeable older woman, the kind of sympathy based on things
one can enumerate, and may change one’s mind about, rather than
the blind warmth of habit?
She stood musing while Anne moved about the studio, putting away
the music, straightening a picture here and there.
“And this is where you’re going to work—”
Anne nodded joyously.
“Lilla apparently expects you to turn it into a dance-hall for her
benefit.”
“Poor Lilla! She can’t see a new room without wanting to fox-trot in it.
Life, for her, wherever she is, consists in going somewhere else in
order to do exactly the same thing.”
Kate was relieved: there was no mistaking the half-disdainful pity of
the tone.
“Well—don’t give her that latch-key!” she laughed, gathering up her
furs.
Anne echoed the laugh. “There are to be only two latch-keys—yours
and mine,” she said; and mother and daughter went gaily down the
steep stairs.

The days, after that, moved on with the undefinable reassurance of


habit. Kate Clephane was beginning to feel herself part of an old-
established routine. She had tried to organize her life in such a way
that it should fit into Anne’s without awkward overlapping. Anne,
nowadays, after her early canter, went daily to the studio and painted
till lunch; sometimes, as the days lengthened, she went back for
another two hours’ work in the afternoon. When the going was too
bad for her morning ride she usually walked to the studio, and Kate
sometimes walked with her, or went through the Park to meet her on
her return. When she painted in the afternoon, Kate would
occasionally drop in for tea, and they would return home together on
foot in the dusk. But Mrs. Clephane was scrupulously careful not to
intrude on her daughter’s working-hours; she held back, not with any
tiresome display of discretion, but with the air of caring for her own
independence too much not to respect Anne’s.
Sometimes, now that she had settled down into this new way of life,
she was secretly aware of feeling a little lonely; there were hours
when the sense of being only a visitor in the house where her life
ought to have been lived gave her the same drifting uprooted feeling
which had been the curse of her other existence. It was not Anne’s
fault; nor that, in this new life, every moment was not interesting and
even purposeful, since each might give her the chance of serving
Anne, pleasing Anne, in some way or another getting closer to Anne.
But this very feeling took a morbid intensity from the fact of having
no common memories, no shared associations, to feed on. Kate was
frightened, sometimes, by its likeness to that other isolated and
devouring emotion which her love for Chris had been. Everything
might have been different, she thought, if she had had more to do, or
more friends of her own to occupy her. But Anne’s establishment,
which had been her grandmother’s, still travelled smoothly enough
on its own momentum, and though the girl insisted that her mother
was now the head of the house, the headship involved little more
than ordering dinner, and talking over linen and carpets and curtains
with old Mrs. Clephane’s house-keeper.
Then, as to friends—was it because she was too much engrossed in
her daughter to make any? Or because her life had been too
incommunicably different from that of her bustling middle-aged
contemporaries, absorbed by local and domestic questions she had
no part in? Or had she been too suddenly changed from a self-
centred woman, insatiable for personal excitements, into that new
being, a mother, her centre of gravity in a life not hers?
She did not know; she felt only that she no longer had time for
anything but motherhood, and must be content to bridge over, as
best she could, the unoccupied intervals. And, after all, the intervals
were not many. Her daughter never appeared without instantly filling
up every crevice of the present, and overflowing into the past and
the future, so that, even in the mother’s rare lapses into
despondency, life without Anne, like life before Anne, had become
unthinkable.
She was revolving this for the thousandth time as she turned into the
Park one afternoon to meet Anne on the latter’s way homeward. The
days were already much longer; the difference in the light, and that
premature languor of the air which comes, in America, before the
sleeping earth seems to expect it, made Mrs. Clephane feel that the
year had turned, that a new season was opening in her new life. She
walked on with the vague sense of confidence in the future which the
first touch of spring gives. The worst of the way was past—how
easily, how smoothly to the feet! Where misunderstanding and failure
had been so probable, she was increasingly sure of having
understood and succeeded. And already she and Anne were making
delightful plans for the spring....
Ahead of her, in a transverse alley, she was disagreeably surprised
by the sight of Lilla Gates. There was no mistaking that tall lounging
figure, though it was moving slowly away from her. Lilla at that hour
in the Park? It seemed curious and improbable. Yet Lilla it was; and
Mrs. Clephane’s conclusion was drawn immediately. “Who is she
waiting for?”
Whoever it was had not come; the perspective beyond Lilla was
empty. After a moment she hastened her step, and vanished behind
a clump of evergreens at the crossing of the paths. Kate did not
linger to watch for her reappearance. The incident was too trifling to
fix the attention; after all, what had one ever expected of Lilla but that
she might be found loitering in unlikely places, in quest of
objectionable people? There was nothing new in that—nor did Kate
even regret not having a glimpse of the objectionable person. In her
growing reassurance about Anne, Lilla’s affairs had lost whatever
slight interest they once offered.
She walked on—but her mood was altered. The sight of Lilla
lingering in that deserted path had called up old associations. She
remembered meetings of the same kind—but was it her own young
figure she saw fading down those far-off perspectives? Well—if it

You might also like