You are on page 1of 67

Database Processing Fundamentals

Design and Implementation 15th


Edition Kroenke Solutions Manual
Visit to download the full and correct content document: https://testbankdeal.com/dow
nload/database-processing-fundamentals-design-and-implementation-15th-edition-kr
oenke-solutions-manual/
INSTRUCTOR’S MANUAL
TO ACCOMPANY

David M. Kroenke | David J. Auer | Scott L. Vandenberg | Robert C. Yoder

40th Anniversary Edition


DATABASE PROCESSING
Fundamentals, Design, and Implementation
15th Edition

Chapter 7
SQL for Database Construction and Application Processing

Prepared By
David J. Auer
Western Washington University
Instructor's Manual to accompany:

Database Processing: Fundamental, Design, and Implementation (15th Edition)


David M. Kroenke | David J. Auer | Scott L. Vandenberg | Robert C. Yoder

Copyright © 2019 Pearson Education, Inc.

All rights reserved. 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, or otherwise, without the prior
written permission of the publisher. Printed in the United States of America.
Chapter Seven – SQL For Database Construction and Application Processing

❖ CHAPTER OBJECTIVES
• To be able to create and manage table structures using SQL statements
• To understand how referential integrity actions are implemented in SQL statements
• To be able to create and execute SQL constraints
• To understand several uses for SQL views
• To be able to use SQL statements to create, use, and manage views
• To gain an understanding of how SQL is used in an application program
• To understand how to create and use functions
• To understand how to create and use triggers
• To understand how to create and use stored procedures

❖ IMPORTANT TEACHING NOTE – READ THIS FIRST!


Chapter 7 is intended to be taught in conjunction with one of these downloadable online
chapters depending on which DBMS product you are using:
• For Microsoft SQL Server 2017, use online Chapter 10A.
• For Oracle Database 12c Release 2 or Oracle Database XE, use online Chapter
10B.
• For MySQL 5.7, use online Chapter 10C.
For each topic discussed in Chapter 7, there is a more detailed and DBMS specific
treatment of the same topic in online Chapters 10A, 10B, and 10C.
When you teach a topic in Chapter 7, extend the coverage with the associated material
in online Chapters 10A, 10B, and 10C.
Assignments from the end of chapter Review Question, Project Questions, Cases and
Projects also can and should be coordinated between Chapter 7 and the online DBMS
specific chapters.
The online Chapters are available for downloading at
http://www.pearsonhighered.com/kroenke/.

Page 7-3
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

❖ ERRATA
[05-MAY-2018 – David Auer] Page 412. The Queen Ann Curiosity Shop Project
Question M has a misspelled word. The corrected question text is:
Write an SQL statement to create a view called EmployeeSupervisorView that shows who, if anyone,
supervises each employee at The Queen Anne Curiosity Shop, and which contains E1.LastName as
EmployeeLastName, E1.FirstName as EmployeeFirstName, E1.Position, E2.Lastname as
SupervisorLastName, and E2.FirstName as SupervisorFirstName. E1 and E2 are two aliases for the
EMPLOYEE table, and are required to run a query on a recursive relationship. Include employees
who do not have a supervisor. Run the statement to create the view, and then test the view with an
appropriate SQL SELECT statement.

[05-MAY-2018 – Scott Vandenberg] Page 416. There is an error in the list of values for
the STORE.Country column. Based on Figure 7-61, possible values should include the
People’s Republic of China, but not Hong Kong because Hong Kong is now part of the
People’s Republic of China. The corrected question text is:
Values of the Country column in the STORE table are restricted to: India, Japan, People’s Republic of
China, Peru, Philippines, Singapore, and United States.

[05-MAY-2018 – David Auer] Page 412. The Queen Ann Curiosity Shop Project
Question M has a misspelled word. The corrected question text is:
Write an SQL statement to create a view called EmployeeSupervisorView that shows who, if anyone,
supervises each employee at The Queen Anne Curiosity Shop, and which contains E1.LastName as
EmployeeLastName, E1.FirstName as EmployeeFirstName, E1.Position, E2.Lastname as
SupervisorLastName, and E2.FirstName as SupervisorFirstName. E1 and E2 are two aliases for the
EMPLOYEE table, and are required to run a query on a recursive relationship. Include employees
who do not have a supervisor. Run the statement to create the view, and then test the view with an
appropriate SQL SELECT statement.

[06-MAY-2018 – Bob Yoder] Page 412. The Queen Ann Curiosity Shop Project
Question Q has an incorrect SQL view name. The corrected question text is:
Write an SQL statement to create a view called CustomerFirstNameFirstSaleSummaryView that
contains SALE.SaleID, SALE.SaleDate, CUSTOMER.CustomerID, the concatenated customer name
using the FirstNameFirst function, SALE_ITEM .SaleItemID, SALE_ITEM.ItemID,
ITEM.ItemDescription, and ITEM.ItemPrice. Run the statement to create the view, and then test the
view with an appropriate SQL SELECT statement.

Page 7-4
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

❖ TEACHING SUGGESTIONS
• If your students have been using Access, now is really the time to switch to Microsoft
SQL Server 2017, Oracle Database, or MySQL 5.7. Refer your students to the
beginning of Online Chapter 10A for Microsoft SQL Server 2017, Online Chapter 10B
for Oracle Database (Oracle Database Express Edition 11g Release 2, aka Oracle
Database XE is heavily recommended), and Online Chapter 10C for MySQL 5.7
setup instructions.
• The SQL examples shown in Chapter 7 and the questions in the end of chapter
material work the best with the Transact-SQL (T-SQL) used in Microsoft SQL Server
2017. If your students are using Microsoft SQL Server 2017, they should be able to
create the tables, populate the tables and run the other SQL commands with little
trouble. The SQL used in Microsoft Access 2016, Oracle Database (PL/SQL), and
MySQL 5.7 varies in their ability to support all the SQL commands used here.
Oracle Database and MySQL do a better job of supporting standard SQL, while
Microsoft Access has significant variations from the standard. In the answers to the
end of chapter questions I have often shown the solution using two or more of the
three DBMSs. Otherwise, I primarily use Microsoft SQL Server 2017. If your
students are using Microsoft Access 2016, Oracle Database, or MySQL 5.7 check
the solutions to the questions before you assign them so that you can tell your
students what to watch out for!
• As discussed in the IM Chapter 2 suggestions, there is a useful teaching technique
that will allow you to demonstrate the SQL queries in the text using MS SQL Server if
you have it available.
• Create a new SQL Server database named Cape-Codd.
• Use the SQL statements in the *.sql text file DBP-e15-MSSQL-Cape-Codd-
Create-Tables.sql to create the Cape Codd database tables (the additional
tables used in the Chapter 2 Review Questions, are also created).
• Use the SQL statements in the *.sql text file DBP-e15-MSSQL-Cape-Codd-
Insert-Data.sql to populate the Cape Codd tables (the additional tables used
in the Chapter 2 Review Questions, are also populated).
• Open the Microsoft SQL Server Management Studio and select the Cape-
Codd database.
• In the Microsoft SQL Server Management Studio, open the *.sql text file DBP-
e15-MSSQL-Cape-Codd-Query-Set-CH02.sql. This file contains all the
queries shown in the Chapter 2 text.
• Highlight the query you want to run, and then click the Execute Query button
to display the results of the query. An example of this is shown in the
following screenshot.
• All of the *.sql text files needed to do this are available in the Instructor’s
Resource Center on the text’s Web site
(www.pearsonhighered.com/kroenke).

Page 7-5
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

• The trick shown for SQL Server 2017 also works for Oracle Database using the
Oracle SQL Developer and for MySQL 5.7 using the MySQL workbench.
• Remind your students that Microsoft Access does not support all SQL constructs.
• Because of the complexity of the SQL statements to construct the View Ridge
Gallery VRG database, the necessary SQL scripts are included in the set of student
data files available at the text’s Web site (www.pearsonhighered.com/kroenke).
• Review Questions 7.04-7.40 are specifically designed to reinforce the most important
basic ideas of creating and populating tables, with a bit on SQL views also included.
These exercises are based on our recent classroom teaching experience, which
taught us the need for some very basic exercises in creating and populating tables
before going on to more complex assignments. This set of exercises is very heavily
recommended!
• Tell your students that a check constraint that provides an enumerated list is often
implemented with a table and a relationship. For example, the constraint CHECK
(Rank IN (‘FR’, ‘SO’, ‘JR’, ‘SR’)) could be implemented by creating a Rank table and
placing the list in that table. Now the Rank attribute becomes a foreign key and
referential integrity enforces the constraint. Changing the list means adding and
deleting from the RANK table.
• The relationship of database applications and the DBMS is sometimes confusing.
For a simple application using a personal DBMS such as Microsoft Access, the
application and the DBMS are nearly indistinguishable. If an application has only a
few forms and reports, and all of these are created using DBMS facilities, then the
application and the DBMS are the same. On the other hand, for an organizational
database processed by say, Oracle Database, any application elements discussed in
this chapter would be provided by application program code completely separate

Page 7-6
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

from the DBMS. It’s easier to understand all of this by focusing on application
functions that must be provided — in some cases by facilities in the DBMS and in
other cases by separate application programs.
• It is important to distinguish between an SQL view (the logical structure of data
elements) and a materialization of the view (a form or report). One SQL view can
have many materializations. While this distinction has always been important, it has
become even more so in light of three-tier architecture.
• Remind students that views can be used to implement certain types of security. Most
commonly, they are used to restrict access to attributes and to restrict actions on
tables. This is discussed in detail in Chapter 9.
• You might also remind students that sometimes SQL views are necessary to
complete certain queries.
• Too often students understand how SQL can be used for interactive query, but do
not really understand its role in application processing. In fact, SQL is far more
frequently used for SQL view processing as described here than it is as an
interactive query tool.
• SQL/Persistent Stored Modules (SQL/PSM), stored procedures and triggers
complete a student’s understanding of how database systems work. Often, we talk
about designing database systems to enforce business rules but find many rules that
we cannot enforce through design alone. Triggers will help enforce most rules that
design cannot enforce.
• SQL *sql files containing the solutions to the questions and projects at the end of the
chapter are available on the text’s Web site (www.pearsonhighered.com/kroenke).

Page 7-7
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

❖ ANSWERS TO REVIEW QUESTIONS


7.1 What does DDL stand for? List the SQL DDL statements.

DDL stands for Data Definition Language. DDL statements include:

• CREATE TABLE

• ALTER TABLE

• DROP TABLE

• TRUNCATE TABLE

7.2 What does DML stand for? List the SQL DML statements.

DML stands for Data Manipulation Language. DML statements include:

• INSERT

• UPDATE

• DELETE

• MERGE

7.3 Explain the meaning of the following expression: IDENTITY (4000, 5).

The IDENTITY keyword is used to modify a column name, and is used to specify surrogate keys.
The first number parameter after IDENTITY specifies the starting value for the surrogate key,
and the second number specifies the increment value for each additional record. Thus a column
named RelationID and modified by IDENTITY (4000, 5) will be a surrogate key named
RelationID with an initial value of 4000 (for the first record in the relation), and with following
values incremented by 5: 4000, 4005, 4010, etc.

Page 7-8
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

For this set of Review Questions, we will create and use a database with a set of tables that will
allow us to compare variations in SQL CREATE TABLE and SQL INSERT statements. The
purpose of these questions is to illustrate different situations that call for specific uses of various
SQL CREATE TABLE and SQL INSERT options.

The database will be named CH07_RQ_TABLES and will contain the following six tables:

CUSTOMER_01 (EmailAddress, LastName, FirstName)

CUSTOMER_02 (CustomerID, EmailAddress, LastName, FirstName)

CUSTOMER_03 (CustomerID, EmailAddress, LastName, FirstName)

CUSTOMER_04 (CustomerID, EmailAddress, LastName, FirstName)

SALE_01 (SaleID, DateOfSale, EmailAddress, SaleAmount)

SALE_02 (SaleID, DateOfSale, CustomerID, SaleAmount)

EmailAddress is a text column containing an email address, and is therefore not a surrogate
key. CustomerID is a surrogate key that starts at 1 and increments by 1. SaleID is a surrogate
key that starts at 20150001 and increases by 1.

The CH07_RQ_TABLES database has the following referential integrity constraints:

EmailAddress in SALE_01 must exist in EmailAddress in CUSTOMER_01

CustomerID in SALE_02 must exist in CustomerID in CUSTOMER_04

The relationship from SALE_01 to CUSTOMER_01 is N:1, O-M.

The relationship from SALE_02 to CUSTOMER_04 is N:1, O-M.

The column characteristics for these tables are shown in Figures 7-35 (CUSTOMER_01), 7-36
(CUSTOMER_02, CUSTOMER_03, and CUSTOMER_04), 7-37 (SALE_01), and 7-38
(SALE_02). The data for these tables are shown in Figures 7-39 (CUSTOMER_01), 7-40
(CUSTOMER_02), 7-41 (CUSTOMER_04), 7-42 (SALE_01), and 7-43 (SALE_02).

7.4 If you are using Microsoft SQL Server, Oracle Database, or MySQL, create a folder in
your Documents folder to save and store the *.sql scripts containing the SQL statements
that you are asked to create in the following Review Questions about the
CH07_RQ_TABLES database.

• For SQL Server Management Studio, create a folder named CH07-RQ-TABLES-


Database in the Projects folder in your SQL Server Management Studio folder.

• For Oracle SQL Developer, create a folder named CH07-RQ-TABLES-Database


in your SQL Developer folder.

Page 7-9
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

• For SQL Workbench, create a folder named CH07-RQ-TABLES-Database in the


Schemas folder in your MySQL Workbench folder.

• If you are using Microsoft Access 2016, create a folder named CH07-Databases
in your DBPe15-Access-2016-Databases folder.

This is self-explanatory. The student will create the appropriate folder to hold the *.sql scripts
created in these Review Questions

7.5 Create a database named CH07_RQ_TABLES.

This is self-explanatory. The student will create the appropriate database base upon which DBMS
product they are using. For further guidance on creating a new database:

• For Microsoft SQL Server 2017, see online Chapter 10A.

• For Oracle Database, see online Chapter 10B.

• For MySQL 5.7, see online Chapter 10C.

7.6 If you are using Microsoft SQL Server, Oracle Database, or MySQL, create and save an
SQL script named CH07-RQ-TABLES-Tables-Data-and-Views.sql to hold the answers to
Review Questions 7.7–7.40. Use SQL script commenting (/* and */ symbols) to write
your answers to Review Questions that require written answers as comments.

If you are running Microsoft Access 2016, create and save a Microsoft Notepad text file
named CH07-RQ-TABLES-Tables-Data-and-Views.txt to hold the answers to Review
Questions 7.7–7.40. After you run each SQL statement in Microsoft Access 2016, copy
your SQL statement to this file.

This is self-explanatory. The student will create an *.sql script named CH07-RQ-TABLES-
Tables-Data-and-Views.sql, unless the student is using Microsoft Access 2016 (which they really
shouldn’t be at this point!), in which case they will create a text file named CH07-RQ-TABLES-
Tables-Data-and-Views.txt to hold certain answers.

7.7 Write and run an SQL CREATE TABLE statement to create the CUSTOMER_01 table.

For Microsoft SQL Server, Oracle Database, and MySQL 5.7:


CREATE TABLE CUSTOMER_01(
EmailAddress VARCHAR(100) NOT NULL,
LastName VARCHAR(25) NOT NULL,
FirstName VARCHAR(25) NOT NULL,
CONSTRAINT CUSTOMER_01_PK PRIMARY KEY(EmailAddress)
);

Page 7-10
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

7.8 Write and run an SQL CREATE TABLE statement to create the CUSTOMER_02 table.

For Microsoft SQL Server:


CREATE TABLE CUSTOMER_02(
CustomerID INT NOT NULL IDENTITY(1, 1),
EmailAddress VARCHAR(100) NOT NULL,
LastName VARCHAR(25) NOT NULL,
FirstName VARCHAR(25) NOT NULL,
CONSTRAINT CUSTOMER_02_PK PRIMARY KEY(CustomerID)
);

Page 7-11
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

For Oracle Database:


Oracle creates primary key surrogate values by using sequences.

CREATE TABLE CUSTOMER_02(


CustomerID INT NOT NULL ,
EmailAddress VARCHAR(100) NOT NULL,
LastName VARCHAR(25) NOT NULL,
FirstName VARCHAR(25) NOT NULL,
CONSTRAINT CUSTOMER_02_PK PRIMARY KEY(CustomerID)
);

CREATE SEQUENCE seqC02 INCREMENT BY 1 START WITH 1;

For MySQL 5.7:


MySQL creates primary key surrogate values by AUTO_INCREMENT, which always
increments by 1. The starting value may be set using an SQL ALTER TABLE statement.

CREATE TABLE CUSTOMER_02(


CustomerID INT NOT NULL AUTO_INCREMENT,
EmailAddress VARCHAR(100) NOT NULL,
LastName VARCHAR(25) NOT NULL,
FirstName VARCHAR(25) NOT NULL,
CONSTRAINT CUSTOMER_02_PK PRIMARY KEY(CustomerID)
);

7.9 Are there any significant differences between the CUSTOMER_01 and CUSTOMER_02
tables? If so, what are they?

CUSTOMER_02 uses a surrogate primary key, while CUSTOMER_01 uses a non-surrogate


primary key.

7.10 Write and run an SQL CREATE TABLE statement to create the CUSTOMER_03 table.

For Microsoft SQL Server:


CREATE TABLE CUSTOMER_03(
CustomerID INT NOT NULL IDENTITY(1, 1),
EmailAddress VARCHAR(100) NOT NULL,
LastName VARCHAR(25) NOT NULL,
FirstName VARCHAR(25) NOT NULL,
CONSTRAINT CUSTOMER_03_PK PRIMARY KEY(CustomerID)
);

Page 7-12
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

For Oracle Database XE:


Oracle creates primary key surrogate values by using sequences.

CREATE TABLE CUSTOMER_03(


CustomerID INT NOT NULL ,
EmailAddress VARCHAR(100) NOT NULL,
LastName VARCHAR(25) NOT NULL,
FirstName VARCHAR(25) NOT NULL,
CONSTRAINT CUSTOMER_03_PK PRIMARY KEY(CustomerID)
);

CREATE SEQUENCE seqC03 INCREMENT BY 1 START WITH 1;

For MySQL 5.7:


MySQL creates primary key surrogate values by AUTO_INCREMENT, which always
increments by 1. The starting value may be set using an SQL ALTER TABLE statement.

CREATE TABLE CUSTOMER_03(


CustomerID INT NOT NULL AUTO_INCREMENT,
EmailAddress VARCHAR(100) NOT NULL,
LastName VARCHAR(25) NOT NULL,
FirstName VARCHAR(25) NOT NULL,
CONSTRAINT CUSTOMER_03_PK PRIMARY KEY(CustomerID)
);

7.11 Are there any significant differences between the CUSTOMER_02 and CUSTOMER_03
tables? If so, what are they?

The table structure is the same, so there are no significant differences between the
CUSTOMER_02 and CUSTOMER_03 tables.

7.12 Write and run an SQL CREATE TABLE statement to create the CUSTOMER_04 table.

For Microsoft SQL Server:


CREATE TABLE CUSTOMER_04(
CustomerID INT NOT NULL IDENTITY(1, 1),
EmailAddress VARCHAR(100) NOT NULL,
LastName VARCHAR(25) NOT NULL,
FirstName VARCHAR(25) NOT NULL,
CONSTRAINT CUSTOMER_04_PK PRIMARY KEY(CustomerID)
);

Page 7-13
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

For Oracle Database XE:


Oracle creates primary key surrogate values by using sequences.

CREATE TABLE CUSTOMER_04(


CustomerID INT NOT NULL ,
EmailAddress VARCHAR(100) NOT NULL,
LastName VARCHAR(25) NOT NULL,
FirstName VARCHAR(25) NOT NULL,
CONSTRAINT CUSTOMER_03_PK PRIMARY KEY(CustomerID)
);

CREATE SEQUENCE seqC04 INCREMENT BY 1 START WITH 1;

For MySQL 5.7:


MySQL creates primary key surrogate values by AUTO_INCREMENT, which always
increments by 1. The starting value may be set using an SQL ALTER TABLE statement.

CREATE TABLE CUSTOMER_04(


CustomerID INT NOT NULL AUTO_INCREMENT,
EmailAddress VARCHAR(100) NOT NULL,
LastName VARCHAR(25) NOT NULL,
FirstName VARCHAR(25) NOT NULL,
CONSTRAINT CUSTOMER_04_PK PRIMARY KEY(CustomerID)
);

7.13 Are there any significant differences between the CUSTOMER_03 and CUSTOMER_04
tables? If so, what are they?

The table structure is the same, so there are no significant differences between the
CUSTOMER_03 and CUSTOMER_04 tables.

7.14 Write and run an SQL CREATE TABLE statement to create the SALE_01 table. Note
that the foreign key is EmailAddress, which references CUSTOMER_01. EmailAddress.
In this database, CUSTOMER_01 and SALE_01 records are never deleted, so that there
will be no ON DELETE referential integrity action. However, you will need to decide how
to implement the ON UPDATE referential integrity action.

For Microsoft SQL Server:


CREATE TABLE SALE_01(
SaleID INT NOT NULL IDENTITY(20150001, 1),
DateOfSale DATE NOT NULL,
EmailAddress VARCHAR(100) NOT NULL,
SaleAmount NUMERIC(7,2) NOT NULL,
CONSTRAINT SALE_PK_01 PRIMARY KEY(SaleID),
CONSTRAINT S_01_C_01_FK FOREIGN KEY(EmailAddress)
REFERENCES CUSTOMER_01(EmailAddress)
ON UPDATE CASCADE
);

Page 7-14
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

For Oracle Database:


Oracle creates primary key surrogate values by using sequences.

CREATE TABLE SALE_01(


SaleID INT NOT NULL,
DateOfSale DATE NOT NULL,
EmailAddress VARCHAR(100) NOT NULL,
SaleAmount NUMERIC(7,2) NOT NULL,
CONSTRAINT SALE_PK_01 PRIMARY KEY(SaleID),
CONSTRAINT S_01_C_01_FK FOREIGN KEY(EmailAddress)
REFERENCES CUSTOMER_01(EmailAddress) );

CREATE SEQUENCE seqS01 INCREMENT BY 1 START WITH 20150001;

For MySQL 5.7:


MySQL creates primary key surrogate values by AUTO_INCREMENT, which always
increments by 1. The starting value may be set using an SQL ALTER TABLE statement.

);
CREATE TABLE SALE_01(
SaleID INT NOT NULL AUTO_INCREMENT,
DateOfSale DATE NOT NULL,
EmailAddress VARCHAR(100) NOT NULL,
SaleAmount NUMERIC(7,2) NOT NULL,
CONSTRAINT SALE_PK_01 PRIMARY KEY(SaleID),
CONSTRAINT S_01_C_01_FK FOREIGN KEY(EmailAddress)
REFERENCES CUSTOMER_01(EmailAddress)
ON UPDATE CASCADE
);

ALTER TABLE SALE_01 AUTO_INCREMENT =20150001;

7.15 In Review Question 7.14, how did you implement the ON UPDATE referential integrity
action? Why?

The ON UPDATE referential integrity action is implemented as CASADE. This is because the
primary key of CUSTOMER_01 (EmailAddress) is not a surrogate key, and may therefore be
changed. Any changes to EmailAdress in CUSTOMER_01 must also be made to corresponding
values in SALE_01.

For Oracle Database:


In Oracle, the ON UPDATE option is not available, so a trigger would need to be created to
enforce this:

CREATE OR REPLACE TRIGGER CustSalesUpdateCascade01


AFTER UPDATE OF EmailAddress ON Customer_01
FOR EACH ROW
BEGIN
UPDATE SALE_01 SET EmailAddress = :new.EmailAddress
WHERE EmailAddress = :old.EmailAddress;
END;
/

Page 7-15
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

7.16 Are there any significant differences between the CUSTOMER_01 and SALE_01 tables?
If so, what are they?

SALE_01 uses a surrogate primary key, while CUSTOMER_01 uses a non-surrogate primary
key.

SALE_01 contains a foreign key with a referential integrity constraint to link it to


CUSTOMER_01, while CUSTOMER_01 does not contain a foreign key.

7.17 Could we have created the SALE_01 table before creating the CUSTOMER_01 table? If
not, why not?

No, because the primary key CUSTOMER_01.EmailAddress must be created before the foreign
key SALE_01.EmailAddress.

7.18 Write and run an SQL CREATE TABLE statement to create the SALE_02 table. Note
that the foreign key is CustomerID, which references CUSTOMER_04.CustomerID. In
this database, CUSTOMER_04 and SALE_02 records are never deleted, so that there
will be no ON DELETE referential integrity action. However, you will need to decide how
to implement the ON UPDATE referential integrity action.

For Microsoft SQL Server:


CREATE TABLE SALE_02(
SaleID INT NOT NULL IDENTITY(20150001, 1),
DateOfSale DATE NOT NULL,
EmailAddress VARCHAR(100) NOT NULL,
SaleAmount NUMERIC(7,2) NOT NULL,
CONSTRAINT SALE_02_PK PRIMARY KEY(SaleID),
CONSTRAINT S_02_C_04_FK FOREIGN KEY(CustomerID)
REFERENCES CUSTOMER_04(CustomerID)
ON UPDATE NO ACTION
);

For Oracle Database:


Oracle creates primary key surrogate values by using sequences.

CREATE TABLE SALE_02(


SaleID INT NOT NULL,
DateOfSale DATE NOT NULL,
CustomerID INT NOT NULL,
SaleAmount NUMERIC(7,2) NOT NULL,
CONSTRAINT SALE_02_PK PRIMARY KEY(SaleID),
CONSTRAINT S_02_C_04_FK FOREIGN KEY(CustomerID)
REFERENCES CUSTOMER_04(CustomerID)
);

CREATE SEQUENCE seqS02 INCREMENT BY 1 START WITH 20150001;

Page 7-16
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

For MySQL 5.7:


MySQL creates primary key surrogate values by AUTO_INCREMENT, which always
increments by 1. The starting value may be set using an SQL ALTER TABLE statement.

);
CREATE TABLE SALE_02(
SaleID INT NOT NULL AUTO_INCREMENT,
DateOfSale DATE NOT NULL,
EmailAddress VARCHAR(100) NOT NULL,
SaleAmount NUMERIC(7,2) NOT NULL,
CONSTRAINT SALE_02_PK PRIMARY KEY(SaleID),
CONSTRAINT S_02_C_04_FK FOREIGN KEY(CustomerID)
REFERENCES CUSTOMER_04(CustomerID)
ON UPDATE NO ACTION
);

ALTER TABLE SALE_02 AUTO_INCREMENT =20150001;

7.19 In Review Question 7.18, how did you implement the ON UPDATE referential integrity
action? Why?

The ON UPDATE referential integrity action is implemented as NO ACTION. This is because


the primary key of CUSTOMER_04 (CustomerID) is a surrogate key, and surrogate key values
are never changed.

For Oracle Database:


In Oracle, the ON UPDATE option is not available, but it doesn’t matter since no action is
necessary.

7.20 Are there any significant differences between the SALE_01 and SALE_02 tables? If so,
what are they?

While both tables use the same structure, they link to different versions of the CUSTOMER table,
and therefore SALE_01 uses ON UPDATE CASCADE while SALE_02 uses ON UPDATE NO
ACTION.

7.21 Could we have created the SALE_02 table before creating the CUSTOMER_04 table? If
not, why not?

No, because the primary key CUSTOMER_04.CustomerID must be created before the foreign
key SALE_02.CustomerID.

Page 7-17
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

7.22 Write and run a set of SQL INSERT statements to populate the CUSTOMER_01 table.

INSERT INTO CUSTOMER_01 (EmailAddress, LastName, FirstName)


VALUES('Robert.Shire@somewhere.com','Shire', 'Robert');
INSERT INTO CUSTOMER_01 (EmailAddress, LastName, FirstName)
VALUES('Katherine.Goodyear@somewhere.com','Goodyear', 'Katherine');
INSERT INTO CUSTOMER_01 (EmailAddress, LastName, FirstName)
VALUES('Chris.Bancroft@somewhere.com','Bancroft', 'Chris');

SELECT * FROM CUSTOMER_01;

7.23 Write and run a set of SQL INSERT statements to populate the CUSTOMER_02 table.
Do not use a bulk INSERT command.

For Microsoft SQL Server and MySQL:


INSERT INTO CUSTOMER_02 (EmailAddress, LastName, FirstName)
VALUES('Robert.Shire@somewhere.com','Shire', 'Robert');
INSERT INTO CUSTOMER_02 (EmailAddress, LastName, FirstName)
VALUES('Katherine.Goodyear@somewhere.com','Goodyear', 'Katherine');
INSERT INTO CUSTOMER_02 (EmailAddress, LastName, FirstName)
VALUES('Chris.Bancroft@somewhere.com','Bancroft', 'Chris');

SELECT * FROM CUSTOMER_02;

For Oracle Database:


Note the use of the Oracle DB nextVal property:
INSERT INTO CUSTOMER_02 VALUES(
seqC02.nextVal, 'Robert.Shire@somewhere.com','Shire', 'Robert');
INSERT INTO CUSTOMER_02 VALUES(
seqC02.nextVal, 'Katherine.Goodyear@somewhere.com','Goodyear', 'Katherine');
INSERT INTO CUSTOMER_02 VALUES(
seqC02.nextVal, 'Chris.Bancroft@somewhere.com','Bancroft', 'Chris');

Page 7-18
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

7.24 Are there any significant differences between the sets of SQL INSERT statements used
to populate the CUSTOMER_01 and CUSTOMER_02 tables? If so, what are they?

Although the SQL code appears identical, the SQL INSERT statements for CUSTOMER_01
contain the primary key EmailAddress values, while the SQL INSERT statements for
CUSTOMER_02 are written anticipating that the values for the surrogate primary key
CustomerID values will be supplied by the DBMS.

7.25 Write and run an SQL INSERT statement to populate the CUSTOMER_03 table. Use a
bulk INSERT command and the data in the CUSTOMER_01 table.

For Microsoft SQL Server and MySQL:


INSERT INTO CUSTOMER_03 (EmailAddress, LastName, FirstName)
SELECT EmailAddress, LastName, FirstName
FROM CUSTOMER_01;

SELECT * FROM CUSTOMER_03;

For Oracle Database:


Note the use of the Oracle DB nextVal property and the use of the alias C for the results of the
SELECT on the CUSTOMER_01 table :
INSERT INTO Customer_03
SELECT seqC03.nextVal, C.EmailAddress, C.LastName, C.FirstName
FROM (SELECT DISTINCT EmailAddress, LastName, FirstName
FROM CUSTOMER_01) C;

7.26 Are there any significant differences between the sets of SQL INSERT statements used
to populate the CUSTOMER_02 and CUSTOMER_03 tables? If so, what are they?

The SQL INSERT statements for CUSTOMER_02 contain the needed data values for the
statements, while the bull insert SQL INSERT statements for CUSTOMER_03 depend upon data
in CUSTOMER_01.

In addition, in order to use the sequence in a bulk insert in Oracle, we needed to use a nested
query in the FROM clause (see RQ 7.25 above).

Page 7-19
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

7.27 Write and run a set of SQL INSERT statements to populate rows 1 through 3 in the
CUSTOMER_04 table. Note that this question involves non-sequential surrogate key
values and is based on techniques for Microsoft SQL Server 2017 in Chapter 10A, for
Oracle Database in Chapter 10B, or for MySQL 5.7 in Chapter 10C, depending upon
which DBMS product you are using.

For Microsoft SQL Server:


/* Be sure IDENTITY_INSERT is OFF for all tables. */

SET IDENTITY_INSERT CUSTOMER_04 OFF

/********************************************************************************/

/* INSERT data for CUSTOMER_04 */

/* Set INDENTITY_INSERT to ON for CUSTOMER_43; */


/* reset it to OFF after non-sequential CUSTOMER data is inserted. */

SET IDENTITY_INSERT CUSTOMER_04 ON

INSERT INTO CUSTOMER_04 (CustomerID, EmailAddress, LastName, FirstName)


VALUES(17, 'Robert.Shire@somewhere.com','Shire', 'Robert');
INSERT INTO CUSTOMER_04 (CustomerID, EmailAddress, LastName, FirstName)
VALUES(23, 'Katherine.Goodyear@somewhere.com','Goodyear', 'Katherine');
INSERT INTO CUSTOMER_04 (CustomerID, EmailAddress, LastName, FirstName)
VALUES(46, 'Chris.Bancroft@somewhere.com','Bancroft', 'Chris');

SET IDENTITY_INSERT CUSTOMER_04 OFF

SELECT * FROM CUSTOMER_04;

For Oracle Database:


The data for CUSTOMER_04 uses non-sequential -- surrogate key values for the primary key
CustomerID, and therefore we insert the value directly instead of using the sequence.
INSERT INTO CUSTOMER_04 (CustomerID, EmailAddress, LastName, FirstName)
VALUES(17, 'Robert.Shire@somewhere.com','Shire', 'Robert');
INSERT INTO CUSTOMER_04 (CustomerID, EmailAddress, LastName, FirstName)
VALUES(23, 'Katherine.Goodyear@somewhere.com','Goodyear', 'Katherine');
INSERT INTO CUSTOMER_04 (CustomerID, EmailAddress, LastName, FirstName)
VALUES(46, 'Chris.Bancroft@somewhere.com','Bancroft', 'Chris');

Page 7-20
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

For MySQL 5.7:


The data for CUSTOMER_04 uses non-sequential -- surrogate key values for the primary key
CustomerID, and therefore we must enter directly instead of using AUTO_INCREMENT as
shown in Rewiew Question 7.12. Since CUSTOMER_04 table was created with the
AUTO_INCREMENT, we use:
ALTER TABLE CUSTOMER_04
MODIFY COLUMN CustomerID INTEGER NOT NULL;

INSERT INTO CUSTOMER_04 (CustomerID, EmailAddress, LastName, FirstName)


VALUES(17, 'Robert.Shire@somewhere.com','Shire', 'Robert');
INSERT INTO CUSTOMER_04 (CustomerID, EmailAddress, LastName, FirstName)
VALUES(23, 'Katherine.Goodyear@somewhere.com','Goodyear', 'Katherine');
INSERT INTO CUSTOMER_04 (CustomerID, EmailAddress, LastName, FirstName)
VALUES(46, 'Chris.Bancroft@somewhere.com','Bancroft', 'Chris');

ALTER TABLE CUSTOMER_04


MODIFY COLUMN CustomerID INTEGER NOT NULL AUTO_INCREMENT;
ALTER TABLE CUSTOMER_04 AUTO_INCREMENT = 47;

7.28 Are there any significant differences between the sets of SQL INSERT statements used
to populate the CUSTOMER_02 table and rows 1-3 of the CUSTOMER_04 table? If so,
what are they?

The data for CUSTOMER_02 uses sequential and non-preexisting surrogate key values for the
primary key CustomerID, and therefore no special coding is needed. In Oracle Databasem we
simply use the sequence created for the purpose.

The data for CUSTOMER_04 uses non-sequential and preexisting surrogate key values for the
primary key CustomerID, and therefore special coding is needed. In Oracle Database, we insert
the value directly instead of using the sequence.

The techniques for handling this type of data is discussed in online Chapter 10A for Microsoft
SQL Server 2017, online Chapter 10B for Oracle Database XE, and online Chapter 10C for
MySQL 5.7.

7.29 Write and run a set of SQL INSERT statements to populate rows 4 through 6 in the
CUSTOMER_04 table. Note that this question involves sequential surrogate key values
and is based on techniques for Microsoft SQL Server 2017 in Chapter 10A, for Oracle
Database in Chapter 10B, or for MySQL 5.7 in Chapter 10C, depending upon which
DBMS product you are using.

For Microsoft SQL Server and MySQL 5.7:


INSERT INTO CUSTOMER_04 (EmailAddress, LastName, FirstName)
VALUES('John.Griffith@somewhere.com','Griffith', 'John');
INSERT INTO CUSTOMER_04 (EmailAddress, LastName, FirstName)
VALUES('Doris.Tierney@somewhere.com', 'Tierney', 'Doris');
INSERT INTO CUSTOMER_04 (EmailAddress, LastName, FirstName)
VALUES('Donna.Anderson@elsewhere.com','Anderson', 'Donna');

SELECT * FROM CUSTOMER_04;

Page 7-21
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

For Oracle Database:


We must recalibrate the sequence to allow for the inserted values,

DROP SEQUENCE seqC04;


CREATE SEQUENCE seqC04 INCREMENT BY 1 START WITH 47;

INSERT INTO CUSTOMER_04 VALUES(


seqC04.nextVal, 'John.Griffith@somewhere.com','Griffith', 'John');
INSERT INTO CUSTOMER_04 VALUES(
seqC04.nextVal, 'Doris.Tierney@somewhere.com', 'Tierney', 'Doris');
INSERT INTO CUSTOMER_04 VALUES(
seqC04.nextVal, 'Donna.Anderson@elsewhere.com','Anderson', 'Donna');

7.30 Are there any significant differences between the sets of SQL INSERT statements used
to populate the CUSTOMER_02 table and rows 4-6 of the CUSTOMER_04 table? If so,
what are they?

No. Because both sets of data use sequential and non-preexisting surrogate key values for the
primary key CustomerID, the SQL INSERT statements are identical, and no special coding is
needed.

7.31 Write and run a set of SQL INSERT statements to populate the SALE_01 table.

For Microsoft SQL Server, and MySQL 5.7 (MySQL uses different data format):
INSERT INTO SALE_01 (DateOfSale, EmailAddress, SaleAmount)
VALUES('14-JAN-2018', 'Robert.Shire@somewhere.com', 234.00);
INSERT INTO SALE_01 (DateOfSale, EmailAddress, SaleAmount)
VALUES('14-JAN-2018', 'Chris.Bancroft@somewhere.com', 56.50);
INSERT INTO SALE_01 (DateOfSale, EmailAddress, SaleAmount)
VALUES('16-JAN-2018', 'Robert.Shire@somewhere.com', 123.00);
INSERT INTO SALE_01 (DateOfSale, EmailAddress, SaleAmount)
VALUES('17-JAN-2018', 'Katherine.Goodyear@somewhere.com', 34.25);

SELECT * FROM SALE_01;

Page 7-22
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

For Oracle Database:


Note the use of the Oracle DB nextVal property:
INSERT INTO SALE_01 VALUES(
seqS01.nextVal, '14-JAN-2015', 'Robert.Shire@somewhere.com', 234.00);
INSERT INTO SALE_01 VALUES(
seqS01.nextVal, '14-JAN-2015', 'Chris.Bancroft@somewhere.com', 56.50);
INSERT INTO SALE_01 VALUES(
seqS01.nextVal, '16-JAN-2015', 'Robert.Shire@somewhere.com', 123.00);
INSERT INTO SALE_01 VALUES(
seqS01.nextVal, '17-JAN-2015', 'Katherine.Goodyear@somewhere.com', 34.25);

7.32 Are there any significant differences between the sets of SQL INSERT statements used
to populate the CUSTOMER_01 table and the SALE_01 table? If so, what are they?

SALE_01 uses surrogate primary key data, while CUSTOMER_01 uses a non-surrogate primary
key data provided in the SQL INSERT statement.

7.33 Could we have populated the SALE_01 table before populating the CUSTOMER_01
table? If not, why not?

No, because the data values primary key CUSTOMER_01.EmailAddress must be created before
the data values of the foreign key SALE_01.EmailAddress.

7.34 Write and run a set of SQL INSERT statements to populate the SALE_02 table.

For Microsoft SQL Server, and MySQL 5.7:


INSERT INTO SALE_02 (DateOfSale, CustomerID, SaleAmount)
VALUES('14-JAN-2018', 17, 234.00);
INSERT INTO SALE_02 (DateOfSale, CustomerID, SaleAmount)
VALUES('14-JAN-2018', 46, 56.50);
INSERT INTO SALE_02 (DateOfSale, CustomerID, SaleAmount)
VALUES('16-JAN-2018', 17, 123.00);
INSERT INTO SALE_02 (DateOfSale, CustomerID, SaleAmount)
VALUES('17-JAN-2018', 23, 34.25);
INSERT INTO SALE_02 (DateOfSale, CustomerID, SaleAmount)
VALUES('18-JAN-2018', 49, 345.00);
INSERT INTO SALE_02 (DateOfSale, CustomerID, SaleAmount)
VALUES('21-JAN-2018', 46, 567.35);
INSERT INTO SALE_02 (DateOfSale, CustomerID, SaleAmount)
VALUES('23-JAN-2018', 47, 78.50);

SELECT * FROM SALE_02;

Page 7-23
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

For Oracle Database:


Note the use of the Oracle DB nextVal property:
INSERT INTO SALE_02 (SaleID, DateOfSale, CustomerID, SaleAmount)
VALUES(seqS02.nextVal, '14-JAN-2018', 17, 234.00);
INSERT INTO SALE_02 (SaleID, DateOfSale, CustomerID, SaleAmount)
VALUES(seqS02.nextVal, '14-JAN-2018', 46, 56.50);
INSERT INTO SALE_02 (SaleID, DateOfSale, CustomerID, SaleAmount)
VALUES(seqS02.nextVal, '16-JAN-2018', 17, 123.00);
INSERT INTO SALE_02 (SaleID, DateOfSale, CustomerID, SaleAmount)
VALUES(seqS02.nextVal, '17-JAN-2018', 23, 34.25);
INSERT INTO SALE_02 (SaleID, DateOfSale, CustomerID, SaleAmount)
VALUES(seqS02.nextVal, '18-JAN-2018', 49, 345.00);
INSERT INTO SALE_02 (SaleID, DateOfSale, CustomerID, SaleAmount)
VALUES(seqS02.nextVal, '21-JAN-2018', 46, 567.35);
INSERT INTO SALE_02 (SaleID, DateOfSale, CustomerID, SaleAmount)
VALUES(seqS02.nextVal, '23-JAN-2018', 47, 78.50);

7.35 Are there any significant differences between the sets of SQL INSERT statements used
to populate the SALE_01 table and the SALE_02 table? If so, what are they?

No. Both tables use surrogate data values for their primary key, and both table rely on preexisting
primary key data to provide referential integrity for their foreign key values.

7.36 Could we have populated the SALE_02 table before populating the CUSTOMER_04
table? If not, why not?

No, because the data values primary key CUSTOMER_04.CustomerID must be created before
the data values of the foreign key SALE_02.CustomerID.

7.37 Write and run an SQL INSERT statement to insert the following record into the SALE_02
table:

What was the result of running this statement? Why did this result occur?

Page 7-24
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

For Microsoft SQL Server, and MySQL 5.7:


INSERT INTO SALE_02 (DateOfSale, CustomerID, SaleAmount)
VALUES('25-JAN-2018', 50, 890.15);

For Microsoft SQL Server:

For Oracle Database:


Note the use of the Oracle DB nextVal property:
INSERT INTO SALE_02 (saleID, DateOfSale, CustomerID, SaleAmount)
VALUES(seqS02.nextVal, '25-JAN-2015', 50, 890.15);

/*** Oracle Database error message appears. ***/

For MySQL 5.7:


/*** MySQL 5.7 error message appears. ***/

The result is an error message. This occurs because the foreign key value SALE_02.CustomerID
does not exist in CUSTOMER_04. This is a violation of the referential integrity constraint
between the tables.

7.38 Write an SQL statement to create a view named Customer01DataView based on the
CUSTOMER_01 table. In the view, include the values of EmailAddress, LastName as
CustomerLastName, and FirstName as CustomerFirstName. Run this statement to
create the view, and then test the view by writing and running an appropriate SQL
SELECT statement.

For Microsoft SQL Server, Oracle Database XE, and MySQL 5.7:
CREATE OR ALTER VIEW Customer01DataView AS
SELECT EmailAddress,
LastName as CustomerLastName,
FirstName as CustomerFirstName
FROM CUSTOMER_01;

SELECT *
FROM Customer01DataView
ORDER BY EmailAddress;

Page 7-25
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

7.39 Write an SQL statement to create a view named Customer04DataView based on the
CUSTOMER_04 table. In the view, include the values of Customer ID, LastName as
CustomerLastName, FirstName as CustomerFirstName, and EmailAddress in that order.
Run this statement to create the view, and then test the view by writing and running an
appropriate SQL SELECT statement.

For Microsoft SQL Server, Oracle Database, and MySQL 5.7:


CREATE OR ALTER VIEW Customer04DataView AS
SELECT CustomerID,
LastName as CustomerLastName,
FirstName as CustomerFirstName,
EmailAddress
FROM CUSTOMER_04;

SELECT *
FROM Customer04DataView
ORDER BY CustomerID;

7.40 Write an SQL statement to create a view named CustomerSalesView based on the the
CUSTOMER_04 and SALE_02 tables. In this view, include the values of Customer ID,
LastName as CustomerLastName, FirstName as CustomerFirstName, EmailAddress,
SaleID, DateOfSale, and SaleAmount in that order. Run this statement to create the
view, and then test the view by writing and running an appropriate SQL SELECT
statement.

For Microsoft SQL Server, Oracle Database, and MySQL 5.7:


Note that Oracle Database does not allow the use of the SQL AS keyword when using table
aliases. Thus, the alias CUSTOMER_04 AS C works in Microsoft SQL Server 2017, but not in
Oracle Database. However, the alias CUSTOMER_04 C (written without the SQL AS keyword)
works in all four DBMS products.
CREATE OR ALTER VIEW CustomerSalesView AS
SELECT C.CustomerID,
LastName as CustomerLastName,
FirstName as CustomerFirstName,
EmailAddress,
SaleID, DateOfSale, SaleAmount
FROM CUSTOMER_04 C JOIN SALE_02 S
ON C.CustomerID = S.CustomerID;

Page 7-26
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

SELECT *
FROM CustomerSalesView
ORDER BY CustomerID;

Page 7-27
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

Wedgewood Pacific Review Qestions

For this set of Review Questions, we will create and use a database for Wedgewood Pacific
(WP) that is similar to the Microsoft Access database we created and used in Chapters 1 and 2.
Founded in 1987 in Seattle, Washington, this company manufactures and sells consumer drone
aircraft. This is an innovative and rapidly developing market. In January, 2016, the FAA said that
181,000 drones (out of the approximately 700,000 drones that may have been sold during the
2015 Christmas season) had been registered under the new FAA drone registration rules.1

WP currently produces three drone models: the Alpha III, the Bravo III, and the Delta IV. These
products are created by WP’s Research and Development group and produced at WP’s
production facilities. WP manufactures some of the parts used in the drones, but also purchases
some parts from other suppliers.

The company is located in two buildings. One building houses the Administration, Legal,
Finance, Accounting, Human Resources, and Sales and Marketing departments, and the
second houses the Information Systems, Research and Development, and Production
departments. The company database contains data about employees; departments; projects;
assets, such as finished goods inventory, parts inventory, and computer equipment; and other
aspects of company operations.

The database will be named WP and will contain the following four tables:

DEPARTMENT (DepartmentName, BudgetCode, OfficeNumber, Phone)


EMPLOYEE (EmployeeNumber, FirstName, LastName, Department, Phone, Email)
PROJECT (ProjectID, Name, Department, MaxHours, StartDate, EndDate)
ASSIGNMENT (ProjectID, EmployeeNumber, HoursWorked)
EmployeeNumber is a surrogate key that starts at 1 and increments by 1. ProjectID is a
surrogate key that starts at 1000 and increases by 100. DepartmentName is the text name of
the department, and is therefore not a surrogate key.

The WP database has the following referential integrity constraints:

Department in EMPLOYEE must exist in Department in DEPARTMENT


Supervisor in EMPLOYEE must exist in EmployeeNumber in EMPLOYEE
Department in PROJECT must exist in Department in DEPARTMENT
ProjectID in ASSIGNMENT must exist in ProjectID in PROJECT
EmployeeNumber in ASSIGNMENT must exist in EmployeeNumber in EMPLOYEE
The relationship from EMPLOYEE to ASSIGNMENT is 1:N, M-O and the relationship from
PROJECT to ASSIGNMENT is 1:N, M-O. The database also has the following business rules:

1
See http://www.msn.com/en-us/lifestyle/smart-living/how-many-us-drones-are-registered-in-the-faa-database/vi-AAgrTT7?
refvid=CCgxby (accessed May 2017).

Page 7-28
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

o If an EMPLOYEE row is to be deleted and that row is connected to any


ASSIGNMENT, the EMPLOYEE row deletion will be disallowed.

o If a PROJECT row is deleted, then all the ASSIGNMENT rows that are
connected to the deleted PROJECT row will also be deleted.

The business sense of these rules is as follows:

o If an EMPLOYEE row is deleted (e.g., if the employee is transferred), then


someone must take over that employee’s assignments. Thus, the application
needs someone to reassign assignments before deleting the employee row.

o If a PROJECT row is deleted, then the project has been canceled, and it is
unnecessary to maintain records of assignments to that project.

The column characteristics for these tables are shown in Figures 1-28 (DEPARTMENT), 1-30
(EMPLOYEE), 2-42 (PROJECT), and 2-44 (ASSIGNMENT). The data for these tables are
shown in Figures 1-29 (DEPARTMENT), 1-31 (EMPLOYEE), 2-43 (PROJECT), and 2-45
(ASSIGNMENT).

Page 7-29
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

Figure 1-28 - Column Characteristics for the WP Database DEPARTMENT Table

Figure 1-30 - Column Characteristics for the WP Database EMPLOYEE Table

Figure 2-42 - Column Characteristics for the WP Database PROJECT Table

Page 7-30
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

Figure 2-44 - Column Characteristics for the WP Database ASSIGNMENT Table

Figure 1-29 – WP Database DEPARTMENT Data

Page 7-31
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

Figure 1-31 – WP Database EMPLOYEE Data

Page 7-32
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

Figure 2-43 – WP Database PROJECT Data

Figure 2-45 – WP Database PROJECT Data

Page 7-33
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

If at all possible, you should run your SQL solutions to the following questions against an actual
database. Because we have already created this database in Microsoft Access, you should use
an SQL-oriented DBMS such as Microsoft SQL Server 2017, Oracle Database, or MySQL 5.7 in
these exercises. Create a database named WP, and create a folder in your My Documents
folder to save and store the *.sql scripts containing the SQL statements that you are asked to
create in the remaining questions pertaining to the WP database in this section and the
following Project Questions section.

● For the SQL Server Management Studio, create a folder named WP-Database in the
Projects folder structure in your My Documents folder.
● In the Oracle SQL Developer folder structure in your My Documents folder, create a
folder named WP-Database.
● For the SQL Workbench, create a folder named WP-Database in the Schemas folder
in your My Documents folder.

If that is not possible, create a new Microsoft Access database named WP-CH07.accdb, and
use the SQL capabilities in these exercises. In all the exercises, use the data types appropriate
for the DBMS you are using.

Write and save an SQL script named WP-Create-Tables.sql that includes the answers to
Review Questions 7.41 through 7.50. Use SQL script commenting (/* and */ symbols) to write
your answers to Review Questions 7.45 and 7.46 as comments so that they cannot be run! Test
and run your SQL statements for Review Questions 7.41, 7.42, 7.43, and 7.44 only. After the
tables are created, run your answers to Review Questions 7.47 through 7.50. Note that after
these four statements have been run the table structure is exactly the same as it was before you
ran them.

7.41 Write a CREATE TABLE statement for the DEPARTMENT table.

For SQL Server, Microsoft Access, Oracle Database and MySQL:

CREATE TABLE DEPARTMENT(


DepartmentName Char(35) NOT NULL,
BudgetCode Char(30) NOT NULL,
OfficeNumber Char(15) NOT NULL,
Phone Char(12) NOT NULL,
CONSTRAINT DEPARTMENT_PK PRIMARY KEY(DepartmentName)
);

Page 7-34
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

7.42 Write a CREATE TABLE statement for the EMPLOYEE table. Email is required and is
an alternate key, and the default value of Department is Human Resources. Cascade
updates but not deletions from DEPARTMENT to EMPLOYEE.

For SQL Server:


CREATE TABLE EMPLOYEE(
EmployeeNumber Int NOT NULL IDENTITY (1, 1),
FirstName Char(25) NOT NULL,
LastName Char(25) NOT NULL,
Department Char(35) NOT NULL DEFAULT 'Human Resources',
Position Char(35) NULL,
Supervisor Int NULL,
OfficePhone Char(12) NULL,
EmailAddress VarChar(100) NOT NULL UNIQUE,
CONSTRAINT EMPLOYEE_PK PRIMARY KEY(EmployeeNumber),
CONSTRAINT EMP_DEPART_FK FOREIGN KEY(Department)
REFERENCES DEPARTMENT(DepartmentName)
ON UPDATE CASCADE,
CONSTRAINT EMP_SUPER_FK FOREIGN KEY (Supervisor)
REFERENCES EMPLOYEE (EmployeeNumber)
);

For Microsoft Access: Microsoft Access SQL statements do NOT support: (1) Parameters on
the Numeric data type, (2) the DEFAULT clause, (3) the ON UPDATE clause, and (4) the ON
DELETE clause. So, this question cannot be fully answered in Microsoft Access compatible
SQL. The required functionality can be set manually in Microsoft Access after the basic table is
created with an SQL statement as shown below:
CREATE TABLE EMPLOYEE(
EmployeeNumber Int NOT NULL,
FirstName Char(25) NOT NULL,
LastName Char(25) NOT NULL,
Department Char(35) NOT NULL,
Position Char(35) NULL,
Supervisor Int NULL,
OfficePhone Char(12) NULL,
EmailAddress VarChar(100) NOT NULL,
CONSTRAINT EMPLOYEE_PK PRIMARY KEY(EmployeeNumber),
CONSTRAINT EMP_DEPART_FK FOREIGN KEY(Department)
REFERENCES DEPARTMENT(DepartmentName),
CONSTRAINT EMP_SUPER_FK FOREIGN KEY (Supervisor)
REFERENCES EMPLOYEE (EmployeeNumber)
);

Page 7-35
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

For Oracle Database: Note that Oracle Database supports ON DELETE CASCADE, but does
not support ON UPDATE CASCADE. Therefore, we cannot cascade updates from PROJECT to
ASSIGNMENT in Oracle Database. Further, Oracle Database does not support the NO ACTION
clause in ON DELETE—since this is the default, Oracle Database simply expects you to only
state ON DELETE CASCADE when this is the desired action. Finally, Oracle Database does not
allow the NOT NULL phrase to be used with DEFAULT—You can use one or the other, but not
both at the same time. Finally, Oracle Database uses SEQUENCES to set surrogate keys.
CREATE TABLE EMPLOYEE(
EmployeeNumber Int NOT NULL,
FirstName Char(25) NOT NULL,
LastName Char(25) NOT NULL,
Department Char(35) NOT NULL,
Position Char(35) NULL,
Supervisor Int NULL,
OfficePhone Char(12) NULL,
EmailAddress VarChar(100) NOT NULL UNIQUE,
CONSTRAINT EMPLOYEE_PK PRIMARY KEY(EmployeeNumber),
CONSTRAINT EMP_DEPART_FK FOREIGN KEY(Department)
REFERENCES DEPARTMENT(DepartmentName),
CONSTRAINT EMP_SUPER_FK FOREIGN KEY (Supervisor)
REFERENCES EMPLOYEE (EmployeeNumber)
);

CREATE SEQUENCE seqEID Increment by 1 Start with 1;

For MySQL: MySQL uses AUTO_INCREMENT to set surrogate keys, but can only use an
increment of 1.
CREATE TABLE EMPLOYEE(
EmployeeNumber Int NOT NULL AUTO_INCREMENT,
FirstName Char(25) NOT NULL,
LastName Char(25) NOT NULL,
Department Char(35) NOT NULL DEFAULT 'Human Resources',
Position Char(35) NULL,
Supervisor Int NULL,
OfficePhone Char(12) NULL,
EmailAddress VarChar(100) NOT NULL UNIQUE,
CONSTRAINT EMPLOYEE_PK PRIMARY KEY(EmployeeNumber),
CONSTRAINT EMP_DEPART_FK FOREIGN KEY(Department)
REFERENCES DEPARTMENT(DepartmentName)
ON UPDATE CASCADE,
CONSTRAINT EMP_SUPER_FK FOREIGN KEY (Supervisor)
REFERENCES EMPLOYEE (EmployeeNumber)
);

ALTER TABLE EMPLOYEE AUTO_INCREMENT=1;

Page 7-36
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

7.43 Write a CREATE TABLE statement for PROJECT table. The default value for MaxHours
is 100. Cascade updates but not deletions from DEPARTMENT to EMPLOYEE.

For SQL Server:


CREATE TABLE PROJECT(
ProjectID Int NOT NULL IDENTITY (1000, 100),
Name Char(50) NOT NULL,
Department Char(35) NOT NULL,
MaxHours Numeric(8,2) NOT NULL DEFAULT 100,
StartDate DateTime NULL,
EndDate DateTime NULL,
CONSTRAINT PROJECT_PK PRIMARY KEY(ProjectID),
CONSTRAINT PROJ_DEPART_FK FOREIGN KEY(Department)
REFERENCES DEPARTMENT(DepartmentName)
ON UPDATE CASCADE
);

For Microsoft Access: Microsoft Access SQL statements do NOT support: (1) Parameters on
the Numeric data type, (2) the DEFAULT clause, (3) the ON UPDATE clause, and (4) the ON
DELETE clause. So, this question cannot be fully answered in Microsoft Access compatible
SQL. The required functionality can be set manually in Microsoft Access after the basic table is
created with an SQL statement as shown below:
CREATE TABLE PROJECT(
ProjectID Int NOT NULL,
Name Char(50) NOT NULL,
Department Char(35) NOT NULL,
MaxHours Numeric NOT NULL,
StartDate DateTime NULL,
EndDate DateTime NULL,
CONSTRAINT PROJECT_PK PRIMARY KEY (ProjectID),
CONSTRAINT PROJ_DEPART_FK FOREIGN KEY(Department)
REFERENCES DEPARTMENT(DepartmentName)
);

For Oracle Database: Note that Oracle Database supports ON DELETE CASCADE, but does
not support ON UPDATE CASCADE. Therefore, we cannot cascade updates from PROJECT to
ASSIGNMENT in Oracle Database. Further, Oracle Database does not support the NO ACTION
clause in ON DELETE—since this is the default, Oracle Database simply expects you to only
state ON DELETE CASCADE when this is the desired action. Finally, Oracle Database does not
allow the NOT NULL phrase to be used with DEFAULT—You can use one or the other, but not
both at the same time. Finally, Oracle Database uses SEQUENCES to set surrogate keys.
CREATE TABLE PROJECT(
ProjectID Int NOT NULL,
Name Char(50) NOT NULL,
Department Char(35) NOT NULL,
MaxHours Numeric(8,2) NOT NULL,
StartDate DateTime NULL,
EndDate DateTime NULL,
CONSTRAINT PROJECT_PK PRIMARY KEY(ProjectID),
CONSTRAINT PROJ_DEPART_FK FOREIGN KEY(Department)
REFERENCES DEPARTMENT(DepartmentName)
);

CREATE SEQUENCE seqPID Increment by 100 Start with 1000;

Page 7-37
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

For MySQL: MySQL uses AUTO_INCREMENT to set surrogate keys, but can only use an
increment of 1.
CREATE TABLE PROJECT(
ProjectID Int NOT NULL AUTO_INCREMENT,
Name Char(50) NOT NULL,
Department Char(35) NOT NULL,
MaxHours Numeric(8,2) NOT NULL DEFAULT 100,
StartDate DateTime NULL,
EndDate DateTime NULL,
CONSTRAINT PROJECT_PK PRIMARY KEY(ProjectID),
CONSTRAINT PROJ_DEPART_FK FOREIGN KEY(Department)
REFERENCES DEPARTMENT(DepartmentName)
ON UPDATE CASCADE
);

ALTER TABLE EMPLOYEE AUTO_INCREMENT=1000;

7.44 Write a CREATE TABLE statement for the ASSIGNMENT table. Cascade only deletions
from PROJECT to ASSIGNMENT; do not cascade either deletions or updates from
EMPLOYEE to ASSIGNMENT.

For SQL Server and MySQL:


CREATE TABLE ASSIGNMENT (
ProjectID Int NOT NULL,
EmployeeNumber Int NOT NULL,
HoursWorked Numeric(6,2) NULL,
CONSTRAINT ASSIGNMENT_PK PRIMARY KEY(ProjectID, EmployeeNumber),
CONSTRAINT ASSIGN_PROJ_FK FOREIGN KEY(ProjectID)
REFERENCES PROJECT(ProjectID)
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT ASSIGN_EMP_FK FOREIGN KEY(EmployeeNumber)
REFERENCES EMPLOYEE(EmployeeNumber)
ON UPDATE NO ACTION
ON DELETE NO ACTION
);

For Microsoft Access: Microsoft Access SQL statements do NOT support: (1) Parameters on
the Numeric data type, (2) the DEFAULT clause, (3) the ON UPDATE clause, and (4) the ON
DELETE clause. So, this question cannot be fully answered in Microsoft Access compatible
SQL. The required functionality can be set manually in Microsoft Access after the basic table is
created with an SQL statement as shown below:
CREATE TABLE ASSIGNMENT (
ProjectID Int NOT NULL,
EmployeeNumber Int NOT NULL,
HoursWorked Number NULL,
CONSTRAINT ASSIGNMENT_PK
PRIMARY KEY (ProjectID, EmployeeNumber),
CONSTRAINT ASSIGN_PROJ_FK FOREIGN KEY (ProjectID)
REFERENCES PROJECT (ProjectID),
CONSTRAINT ASSIGN_EMP_FK FOREIGN KEY (EmployeeNumber)
REFERENCES EMPLOYEE (EmployeeNumber)
);

Page 7-38
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

For Oracle Database: Note that Oracle Database supports ON DELETE CASCADE, but does
not support ON UPDATE CASCADE. Therefore, we cannot cascade updates from PROJECT to
ASSIGNMENT in Oracle Database. Further, Oracle Database does not support the NO ACTION
clause in ON DELETE—since this is the default, Oracle Database simply expects you to only
state ON DELETE CASCADE when this is the desired action. Finally, Oracle Database does not
allow the NOT NULL phrase to be used with DEFAULT—You can use one or the other, but not
both at the same time.
CREATE TABLE ASSIGNMENT (
ProjectID Int NOT NULL,
EmployeeNumber Int NOT NULL,
HoursWorked Number(6,2) NULL,
CONSTRAINT ASSIGNMENT_PK PRIMARY KEY(ProjectID, EmployeeNumber),
CONSTRAINT ASSIGN_PROJ_FK FOREIGN KEY(ProjectID)
REFERENCES PROJECT(ProjectID)
ON DELETE CASCADE,
CONSTRAINT ASSIGN_EMP_FK FOREIGN KEY(EmployeeNumber)
REFERENCES EMPLOYEE(EmployeeNumber)
);

7.45 Modify your answer to Review Question 7.7 to include the constraint that StartDate be
prior to EndDate.

We can either add a CONSTRAINT line directly to the SQL statement in Review Question 7.5,
or we can use an ALTER TABLE statement. MySQL will run, but does not enforce the CHECK
constraint.

For SQL Server, Oracle Database and MySQL:


/* CONSTRAINT LINE TO BE ADDED TO Review Question 7.5 */

CONSTRAINT DateValuesCheck CHECK (StartDate < EndDate),

/* ALTER TABLE SQL Statement */

ALTER TABLE PROJECT


ADD CONSTRAINT DateValuesCheck CHECK (StartDate < EndDate);

For Microsoft Access: Microsoft Access SQL statements do NOT support the CHECK clause,
so this question cannot be fully answered in Microsoft Access compatible SQL. The required
functionality can be set manually in Microsoft Access after the basic table is created with the
SQL statement used in question 7.5.

Page 7-39
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

7.46 Write an alternate SQL statement that modifies your answer to question 7.7 to make the
relationship between EMPLOYEE and ASSIGNMENT a 1:1 relationship.
A 1:1 relationship between EMPLOYEE and ASSIGNMENT means that
ASSIGNMENT.EmployeeNumber must be unique.
We can either add a CONSTRAINT line directly to the SQL statement in Review Question 7.6,
or we can use an ALTER TABLE statement.
For SQL Server, Oracle Database and MySQL:
/* CONSTRAINT LINE TO BE ADDED TO Review Question 7.6 */

CONSTRAINT ASSIGNENT_AK1 UNIQUE(EmployeeNumber),

/* ALTER TABLE SQL Statement */

ALTER TABLE ASSIGNMENT


ADD CONSTRAINT ASSIGNENT_AK1 UNIQUE(EmployeeNumber);

For Microsoft Access: Microsoft Access SQL statements do NOT support: (1) Parameters on
the Numeric data type, (2) the DEFAULT clause, (3) the ON UPDATE clause, and (4) the ON
DELETE clause. So, this question cannot be fully answered in Microsoft Access compatible
SQL. The required functionality can be set manually in Microsoft Access after the basic table,
named ASSIGNMENT_2 in the work below, is created with an SQL statement as shown below:
CREATE TABLE ASSIGNMENT_2 (
ProjectID Int NOT NULL,
EmployeeNumber Int NOT NULL,
HoursWorked Number NULL,
CONSTRAINT ASSIGNMENT_PK
PRIMARY KEY (ProjectID, EmployeeNumber),
CONSTRAINT ASSIGN_PROJ_FK FOREIGN KEY (ProjectID)
REFERENCES PROJECT (ProjectID)
);

Note that the Indexed property for EmployeeNumber is set to Yes (No Duplicates):

Page 7-40
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

Note the 1:N EMPLOYEE-to-ASSIGNMENT relationship and the 1:1 EMPLOYEE-to-


ASSIGNMENT_2 relationship:

7.47 Write an ALTER statement to add the column AreaCode to EMPLOYEE. Assume that
AreaCode is not required.

For all:
ALTER TABLE EMPLOYEE
ADD AreaCode Char(3) NULL;

7.48 Write an ALTER statement to remove the column AreaCode from EMPLOYEE.

For all:
ALTER TABLE EMPLOYEE
DROP COLUMN AreaCode;

7.49 Write an ALTER statement to make Phone an alternate key in EMPLOYEE.

For all:
ALTER TABLE EMPLOYEE
ADD CONSTRAINT EMPLOYEE_AK2 UNIQUE(Phone);

7.50 Write an ALTER statement to drop the constraint that Phone is an alternate key in
EMPLOYEE.

For all except MySQL:


ALTER TABLE EMPLOYEE
DROP CONSTRAINT EMPLOYEE_AK2;

For MySQL:
Use DROP INDEX instead – see MySQL code in IRC.

Page 7-41
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

Create SQL scripts to answer Review Questions 7.51 through 7.56. Write the answer to
Review Question 7.55 as an SQL text comment, but include it in your script. Write the
answer to Review Question 7.56 as an SQL comment so that it cannot be run.

NOTE: Answers to Review Questions 7.51 – 7.56 show the correct INSERT statements for
SQL Server 2017. These statements will also work with Microsoft Access. HOWEVER, they
will need to be modified for Oracle Database (Sequence numbers and dates) and MySQL
(dates). See the chapters on Oracle Database (Online Chapter 10B) and MySQL 5.7 (Online
Chapter 10C) for a discussion of the necessary modifications.

7.51 Write INSERT statements to add the data shown in Figure 1-29 to the DEPARTMENT
table. Run these statements to populate the DEPARTMENT table. [Hint: Write and test
an SQL script, and then run the script. Save the script as WP-Insert-DEPARTMENT-
Data.sql for future use.]
/***** DEPARTMENT DATA ************************************************/

INSERT INTO DEPARTMENT VALUES('Administration', 'BC-100-10', 'BLDG01-210',


'360-285-8100');
INSERT INTO DEPARTMENT VALUES('Legal', 'BC-200-10', 'BLDG01-220',
'360-285-8200');
INSERT INTO DEPARTMENT VALUES('Human Resources', 'BC-300-10', 'BLDG01-230',
'360-285-8300');
INSERT INTO DEPARTMENT VALUES('Finance', 'BC-400-10', 'BLDG01-110',
'360-285-8400');
INSERT INTO DEPARTMENT VALUES('Accounting', 'BC-500-10', 'BLDG01-120',
'360-285-8405');
INSERT INTO DEPARTMENT VALUES('Sales and Marketing', 'BC-600-10',
'BLDG01-250', '360-287-8500');
INSERT INTO DEPARTMENT VALUES('InfoSystems', 'BC-700-10', 'BLDG02-210',
'360-287-8600');
INSERT INTO DEPARTMENT VALUES('Research and Development', 'BC-800-10',
'BLDG02-250', '360-287-8700');
INSERT INTO DEPARTMENT VALUES('Production', 'BC-900-10', 'BLDG02-110',
'360-287-8800');

Page 7-42
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

7.52 Write INSERT statements to add the data shown in Figure 1-31 to the EMPLOYEE
table. Run these statements to populate the EMPLOYEE table. [Hint: Write and test an
SQL script, and then run the script. Save the script as WP-Insert-EMPLOYEE-Data.sql
for future use.]
/***** EMPLOYEE DATA *************************************************/

INSERT INTO EMPLOYEE


(FirstName, LastName, Department, Position, OfficePhone, EmailAddress)
VALUES(
'Mary', 'Jacobs', 'Administration', 'CEO', '360-285-8110',
'Mary.Jacobs@WP.com');
INSERT INTO EMPLOYEE VALUES(
'Rosalie', 'Jackson', 'Administration', 'Admin Assistant', 1,
'360-285-8120', 'Rosalie.Jackson@WP.com');
INSERT INTO EMPLOYEE VALUES(
'Richard', 'Bandalone', 'Legal', 'Attorney', 1,
'360-285-8210', 'Richard.Bandalone@WP.com');
INSERT INTO EMPLOYEE VALUES(
'George', 'Smith', 'Human Resources', 'HR3', 1,
'360-285-8310', 'George.Smith@WP.com');
INSERT INTO EMPLOYEE VALUES(
'Alan', 'Adams', 'Human Resources', 'HR1', 4,
'360-285-8320', 'Alan.Adams@WP.com');
INSERT INTO EMPLOYEE VALUES(
'Ken', 'Evans', 'Finance', 'CFO', 1,
'360-285-8410', 'Ken.Evans@WP.com');
INSERT INTO EMPLOYEE VALUES(
'Mary', 'Abernathy', 'Finance', 'FA3', 6,
'360-285-8420', 'Mary.Abernathy@WP.com');
INSERT INTO EMPLOYEE VALUES(
'Tom', 'Caruthers', 'Accounting', 'FA2', 6,
'360-285-8430', 'Tom.Caruthers@WP.com');
INSERT INTO EMPLOYEE VALUES(
'Heather', 'Jones', 'Accounting', 'FA2', 6,
'360-285-8440', 'Heather.Jones@WP.com');
INSERT INTO EMPLOYEE VALUES(
'Ken', 'Numoto', 'Sales and Marketing', 'SM3', 1,
'360-287-8510', 'Ken.Numoto@WP.com');
INSERT INTO EMPLOYEE VALUES(
'Linda', 'Granger', 'Sales and Marketing', 'SM2', 10,
'360-287-8520', 'Linda.Granger@WP.com');
INSERT INTO EMPLOYEE VALUES(
'James', 'Nestor', 'InfoSystems', 'CIO', 1,
'360-287-8610', 'James.Nestor@WP.com');
INSERT INTO EMPLOYEE
(FirstName, LastName, Department, Position, Supervisor, EmailAddress)
VALUES(
'Rick', 'Brown', 'InfoSystems', 'IS2', 12, 'Rick.Brown@WP.com');
INSERT INTO EMPLOYEE VALUES(
'Mike', 'Nguyen', 'Research and Development', 'CTO', 1,
'360-287-8710', 'Mike.Nguyen@WP.com');
INSERT INTO EMPLOYEE VALUES(
'Jason', 'Sleeman', 'Research and Development', 'RD3', 14,
'360-287-8720', 'Jason.Sleeman@WP.com');
INSERT INTO EMPLOYEE VALUES(
'Mary', 'Smith', 'Production', 'OPS3', 1,
'360-287-8810', 'Mary.Smith@WP.com');

Page 7-43
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

INSERT INTO EMPLOYEE VALUES(


'Tom', 'Jackson', 'Production', 'OPS2', 16,
'360-287-8820', 'Tom.Jackson@WP.com');
INSERT INTO EMPLOYEE VALUES(
'George', 'Jones', 'Production', 'OPS2', 17,
'360-287-8830', 'George.Jones@WP.com');
INSERT INTO EMPLOYEE
(FirstName, LastName, Department, Position, Supervisor, EmailAddress)
VALUES(
'Julia', 'Hayakawa', 'Production', 'OPS1', 17, 'Julia.Hayakawa@WP.com');
INSERT INTO EMPLOYEE
(FirstName, LastName, Department, Position, Supervisor, EmailAddress)
VALUES(
'Sam', 'Stewart', 'Production', 'OPS1', 17, 'Sam.Stewart@WP.com');

7.53 Write INSERT statements to add the data shown in Figure 2-43 to the PROJECT table.
Run these statements to populate the PROJECT table. [Hint: Write and test an SQL
script, and then run the script. Save the script as WP-Insert-PROJECT-Data.sql for
future use.]
/***** PROJECT DATA ***************************************************/

INSERT INTO PROJECT VALUES(


'2018 Q3 Production Plan', 'Production', 100.00,
'10-MAY-18', '15-JUN-18');
INSERT INTO PROJECT VALUES(
'2018 Q3 Marketing Plan', 'Sales and Marketing', 135.00,
'10-MAY-18', '15-JUN-18');
INSERT INTO PROJECT VALUES(
'2018 Q3 Portfolio Analysis', 'Finance', 120.00,
'05-JUL-18', '25-JUL-18' );
INSERT INTO PROJECT VALUES(
'2018 Q3 Tax Preparation', 'Accounting', 145.00,
'10-AUG-18', '15-OCT-18');

Page 7-44
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing

INSERT INTO PROJECT VALUES(


'2018 Q4 Production Plan', 'Production', 100.00,
'10-AUG-18', '15-SEP-18');
INSERT INTO PROJECT VALUES(
'2018 Q4 Marketing Plan', 'Sales and Marketing', 135.00,
'10-AUG-18', '15-SEP-18');
INSERT INTO PROJECT (ProjectName, Department, MaxHours, StartDate)
VALUES(
'2018 Q4 Portfolio Analysis', 'Finance', 140.00, '05-OCT-18');

7.54 Write INSERT statements to add the data shown in Figure 2-45 to the ASSIGNMENT
table. Run these statements to populate the ASSIGNMENT table. [Hint: Write and test
an SQL script, and then run the script. Save the script as WP-Insert-ASSIGNMENT-
Data.sql for future use.]
/***** ASSIGNMENT DATA ************************************************/

INSERT INTO ASSIGNMENT VALUES(1000, 1, 30.0);


INSERT INTO ASSIGNMENT VALUES(1000, 6, 50.0);
INSERT INTO ASSIGNMENT VALUES(1000, 10, 50.0);
INSERT INTO ASSIGNMENT VALUES(1000, 16, 75.0);
INSERT INTO ASSIGNMENT VALUES(1000, 17, 75.0);
INSERT INTO ASSIGNMENT VALUES(1100, 1, 30.0);
INSERT INTO ASSIGNMENT VALUES(1100, 6, 75.0);
INSERT INTO ASSIGNMENT VALUES(1100, 10, 55.0);
INSERT INTO ASSIGNMENT VALUES(1100, 11, 55.0);
INSERT INTO ASSIGNMENT VALUES(1200, 3, 20.0);
INSERT INTO ASSIGNMENT VALUES(1200, 6, 40.0);
INSERT INTO ASSIGNMENT VALUES(1200, 7, 45.0);
INSERT INTO ASSIGNMENT VALUES(1200, 8, 45.0);
INSERT INTO ASSIGNMENT VALUES(1300, 3, 25.0);
INSERT INTO ASSIGNMENT VALUES(1300, 6, 40.0);
INSERT INTO ASSIGNMENT VALUES(1300, 8, 50.0);
INSERT INTO ASSIGNMENT VALUES(1300, 9, 50.0);
INSERT INTO ASSIGNMENT VALUES(1400, 1, 30.0);
INSERT INTO ASSIGNMENT VALUES(1400, 6, 50.0);
INSERT INTO ASSIGNMENT VALUES(1400, 10, 50.0);

Page 7-45
Copyright © 2019Pearson Education, Inc.
Another random document with
no related content on Scribd:
sixteenths which he owned gave him the whip hand, and that he has
held ever since.
Now, no large block of common stock appears to be held by any
individual, corporation, or other government. Indeed, at a meeting
some years ago the largest shareholder outside of Great Britain was
a Frenchman, who had a little more than fifteen hundred shares.
That twenty million dollars was one of the best investments John
Bull has ever made, his holdings to-day being worth many times
what he paid for them. He has already received from it many millions
of dollars in dividends, and by his control of the canal has
enormously increased his power and prestige among the nations of
the world. His money gain, however, is not quite as great as that of
the original stockholders. They paid only about one hundred dollars
per share while he paid a little more than one hundred and thirteen
dollars.
I know the Panama Canal well. I visited it when it was in the hands
of the French, and I have spent several weeks there during
American control. I went over it from end to end with our engineers;
watched the steam shovels gouging the earth out of the Culebra Cut,
and travelled in a canoe down that part of it which was once the
Chagres River. I have also gone through the Suez Canal at three
different times and have made many notes of its construction.
The two undertakings are vitally different. The Suez Canal is little
more than a great ditch through the desert, and although it is just
about twice as big as Panama it does not compare with the latter in
the engineering difficulties of its construction. The ground here is
comparatively level. That of the Panama Canal route is up hill and
down, going right across the backbone of the Andes. The amount
excavated here was one hundred million cubic yards, or just about
one hundred million tons of dead weight. On one of my visits to
Panama I figured that the excavation of Culebra would just equal a
ditch three feet wide and three feet deep and long enough to go two
times around this twenty-five-thousand-mile globe with ten thousand
miles of ditch to spare.
Twenty thousand and more of the Egyptian fellahs were employed
upon the Suez Canal at a time, and they scooped up much of the dirt
in their hands and carried it away in baskets. At the start men were
paid from ten to fifteen cents a day and boys under twelve only five
cents. After a time they were not paid at all. The Khedive agreed to
furnish all the labourers, and they worked for the French under the
lash just as the Hebrews did for the Egyptians in the days of
Pharaoh ages ago. With up-to-date canal-dredging machinery and
steam shovels the work of digging the canal at Suez could perhaps
be reproduced at one half its original cost. The actual cost was
probably quadrupled through the money spent in graft,
extravagance, and high interest rates by the French and Egyptians in
connection with it. When Ismail Pasha was forced from the throne he
left Egypt in debt to the amount of five hundred million dollars, most
of which was directly or indirectly caused by canal expenditures.
One would think that Egypt ought to receive a big revenue for the
right of way through her country and for the canal which her money
and her people practically built. By the original concession with Said
Pasha she was to receive fifteen percent of the net profits for the
entire term of the concession, which was ninety-nine years. But after
Ismail Pasha was deposed, the Egyptian government, finding itself
without money or credit, sold this claim on the canal profits to the
Crédit Foncier of France for a little more than four million dollars, and
the only interest it now has in the canal is in the trade which the
ships passing through bring to the country. Had Egypt retained that
fifteen per cent. it would have been receiving millions of dollars a
year from the tolls, and within a short time it could have recouped
itself for all Ismail Pasha’s extravagances. During the term of the
concession it could easily have repaid its debt to Turkey, and could
have made itself one of the richest countries of the world. As it is, the
canal, with all its property, becomes the possession of Egypt in 1968,
when the receipts at the present ratio of increase will be so
enormous as to make it, in proportion to its population, a Crœsus
among the nations of the world.
I spent all of last night on the Suez Canal. It was afternoon when
our ship left Port Said, and as the darkness came on we were in the
heart of the Arabian Desert. The air was clear, and the scenes were
weird but beautiful. The stars of the tropics, brighter by far than our
stars at home, made the heavens resplendent, while a great round
moon of burning copper turned the famous waterway into a stream
of molten silver. As we ploughed our way through, we could look out
over the silent desert of Arabia, and now and then see a caravan of
long-legged camels with their ghost-like riders bobbing up and down
under the moon. Our own pathway was made brighter by electric
lights. We had one blazing globe at our masthead, fed by a dynamo
on deck, and another at our prow. The latter threw its rays this way
and that across the channel in front of the steamer, making the
waters an opalescent blue like that of the Blue Grotto of Capri. We
passed many ships. In the distance they appeared only as two
blazing eyes—the reflectors which all vessels are required to keep
lighted as they pass through. As the ships came nearer they rose up
like spectres from the water, the masses of hulls and rigging back of
the fiery eyes making one think of demons about to attack.
The trip through the canal is slow, for the ships are allowed to go
only five or six miles an hour. Now and then they have to tie up to
posts, which have been set along both sides of the canal all the way
from Port Said to Suez. The canal rules require that when two ships
meet one must stop and hug the bank until the other has passed by.
Parts of the banks are walled with stones to prevent the sand from
falling in and filling up the canal, but notwithstanding this the dredges
have to be kept at work all the year round. Not far from Port Said I
saw great steam pumps sucking the sand from the bottom of the
channel and carrying it through pipes far out over the desert, and I
am told that the process of cleaning and deepening the waterway is
always going on.
There are stations, or guard houses, at intervals along the course
of the waterway and a few small towns have grown up here and
there. While the boat was stopping at one of these, a dirty Arab
brought alongside a leg of raw mutton. He offered to sell it to the
passengers but found no buyer. Outside of these towns and the
guard houses we see few signs of life. Here a camel caravan trots
along over the desert. There a flock of long-necked cranes springs
from the water into the air. When the sun is right, away across the
hot desert at the side of the ship there looms up out of the sands a
strange ship on other waters, apparently as real as those through
which we are moving. That is the wonderful mirage of the desert,
which so often deceives the thirsty traveller passing through it on
camels. As we approach it, it soon fades and disappears like a
veritable castle of the air.
The Suez Canal of to-day is far different from that which was
opened in 1869. As originally planned, the channel was less than
twenty-five feet deep and so narrow that it could not have
accommodated the shipping which goes through it nowadays. It has
since been widened so that its average width at the surface is about
three hundred feet, and the curves in it have been straightened so as
to shorten the time of transit and enable ships to pass the more
easily. The shipping facilities have been greatly improved both at
Port Tewfik and at Port Said. At Port Said the coaling arrangements
have been so improved that the largest steamers can load
thousands of tons in a very few hours.
The chief towns on the canal are Port Said, Ismailia, and Suez.
Port Said is at the northern end of the canal where we took the
steamer. This city, long said to be the wickedest and most dissipated
station on the way from London to the Far East, was made and lives
by the canal, the harbour being full of shipping from one year’s end
to another.
Ismailia, midway of the canal, is still scarcely more than a small
town. It is now said to be a healthful place, although at one time it
was malarial. The Arabs call it the “cleansed tomb.” This town is at
the end of the fresh-water canal which was made during the building
of the Suez Canal to supply the workmen with water, and is not far
from Zagazig and the old Land of Goshen.
Suez, which is a small-sized city with several thousand
Europeans, is connected by train with Port Said, and also with Cairo
and other parts of Egypt. The city is about thirteen hundred miles
from Aden, Arabia, and just twenty-nine hundred and nineteen miles
from Mombasa, where we are to enter the Colony of Kenya and
make our way by rail across country to the Great Lakes.
CHAPTER XXVI
DOWN THE RED SEA

The Red Sea is red hot! I have steamed many miles along the
Equator, but this salt-water corridor leading to the Indian Ocean is
much hotter. As deserts shut in the Red Sea on both sides, there are
no fresh streams to cool it, and the tropical sun beats down upon the
waters and sands from January to December. As a result, the
temperature of the water at the surface is often one hundred degrees
above zero, and it steams the air like a vast hot-water plant. The
sun’s rays are bottled up by the deserts, which then act as enormous
radiators. Consequently, the atmosphere is suffocating, and there
seems to be only a trembling sheet of blue steel between us and the
lower regions. Indeed, were it not for the electric fan in my cabin I
should be unable to write. Outside upon deck we have double roofs
of canvas to protect us from the sun, and many of the passengers
sleep up there to escape the heat of the rooms below. Last night, in
addition to the heat, we had to contend with a sandstorm, which
covered our ship with red dust so fine that it got through the
portholes and even into our beds. That storm came from Arabia, and
may have swallowed some of the thousands of Mohammedan
pilgrims on their way to Mecca.
As our ship went through this mighty cauldron we passed Jidda, in
Arabia, where, according to the Mohammedans, Eve lies buried.
With the ship’s glass we could almost see the place where lies the
greatest grandmother of all mankind. She rests outside the city wall
in a tomb four hundred feet long and a mosque rises over her dust.
The Mohammedan story has it that when Adam and Eve were
banished from the Garden of Eden a strong west wind wafted the
fairy form of Eve to Arabia, while Adam, with his heavier weight, fell
down in Ceylon. There is a string of coral keys running from Ceylon
to Hindustan, still known as Adam’s Bridge, over which he started
out on his long hunt for Eve. It took him two hundred years to find
her, and the meeting was somewhere near Mecca. What became of
Adam’s bones the story does not say.
On the map, the Red Sea looks like a slit between Asia and Africa,
but this slit is actually two hundred miles wide in some places and
twelve hundred miles long, or nearly half the distance from Suez to
Mombasa, my destination on the east coast of Africa. Much of it is so
deep that if the Blue Ridge Mountains were set in it only their higher
peaks would show. It is so long that if it began at Ireland and
extended westward across the Atlantic, it would reach halfway to
Canada. If it could be lifted up and laid down upon the United States
with Suez at Philadelphia, Bab-el-Mandeb would be a hundred miles
or so beyond Omaha, Nebraska, and all the way between would be
a canal as wide as from New York to Washington, or wide enough to
accommodate all the navies of the world abreast, and leave a
hundred miles or more to spare.
This great waterway narrows almost to a point at each end. At
Bab-el-Mandeb, where it leaves the Indian Ocean, it is no wider than
the English Channel at Dover; at the north it is lost at the Suez
Canal. Starting at Bab-el-Mandeb, the coasts broaden out and then
run almost straight to the upper end, where they fork into two gulfs
inclosing the lower part of the Sinai Peninsula. These two gulfs are
those of Suez and Akabah. The Gulf of Suez is one hundred and
seventy miles long, and has been joined to the Mediterranean by the
Suez Canal. The Gulf of Akabah is one hundred and ten miles long,
and for a time there was talk of making a canal from it to the
Mediterranean.
The air on the Red Sea is so salty that one can almost eat eggs
without seasoning. If one hundred pounds of its waters are boiled
down, four pounds of salt will be found in the bottom of the kettle.
The evaporation is so great that were it not for the inflow of the
Indian Ocean the sea would, within less than a century, vanish in the
air and leave in its place one immense block of salt.
I had expected to find the Red Sea coasts more thickly populated.
There are no cities of any size and very few villages. Suez has large
docks, but its trade is small, and it has nothing like the growth which
men thought would come with the use of the canal.
Have you ever heard of the town of Kosseir? It is a Red Sea port
on the west coast some distance south of Suez which at one time
had a great trade. It was formerly the end of a caravan route from
the Nile, and the Children of Israel crossed over that way and took
boats for the Sinai Peninsula to reach the mountains where Moses
received the Commandments.
To-day Kosseir is a stopping place for Egyptian pilgrims on their
way to Jidda. It used to be much more important in that respect than
now. It had many inns and hotel tents outside, and was well supplied
with dancing girls and the other side-show features of a true
pilgrimage centre. Then the Suez Canal came and killed it. Its big
houses fallen to ruins, the port has become a village of one-story
huts. There are emerald mines near it, however, and the desert
about shows evidences of having been once worked for gold.
I regret that I was not able to stop at Jidda, the port of Mecca, to
which I have already referred. It is one of the most interesting places
on the Red Sea, for one hundred thousand or more pilgrims pass
through it every year. While at Omdurman, in the Sudan, I saw
something like fourteen hundred Mohammedans on their way by
railroad across the Nubian Desert to Port Sudan where they
expected to get a ship for Jidda. Some of them had been ten years
on the way, yet their religious enthusiasm had not waned. They had
started out upon camels from the borders of Timbuktu and had been
forced to sell their mounts to buy food. After that they had walked
from oasis to oasis earning enough money to carry them onward.
There were so many in the party that the British government officials
had to divide them up into batches and send on a trainload or so at a
time.
In the centuries since the worship of Mohammed began millions of
pilgrims have walked over the sixty-five miles of hot sand from Jidda
to Mecca. Worshippers go thither from all parts of North Africa and
from the eastern coast of the Mediterranean as well as from India
and southern Arabia. Jidda takes her toll from each of them. The
people live by fleecing the devotees. The town, though full of hotels,
is noted for its discomforts. It has a poor water supply and after each
big rain there is an epidemic of fever.
The projected railroad from Jidda to Mecca will probably pay well,
for the travel is enormous. Twenty-five years ago more than sixty
thousand Mohammedans came annually by sea to make their way
over the sands to Mecca and Medina. There are perhaps half again
as many more to-day, and the railroad will so reduce the cost of the
trip that the number of worshippers will be greatly increased. Indeed,
the day may come when some Mohammedan tourist agent will be
selling to pilgrims from all parts of the Moslem world round-trip
tickets to the birthplace of the Prophet, including admission to the
Kaaba.
With Mecca accessible by railroad there may be a chance for
Christians to visit the holy city of Islam. All who have been there in
the past have had to go in disguise, and the man who would attempt
it to-day takes his life in his hand. The railroad will be officered by
Mohammedans, and it is doubtful whether they will take Christians
as passengers. They will have to cater to the pilgrims, as it is from
them that their traffic must come.
Meantime, without wishing to act as did the fox who called the
grapes sour, I do not believe there is much to see in Mecca, after all.
The town lies in a hot, arid valley watered for most of the year by a
few brackish wells and some cisterns. The best water, which comes
in from Arafat through a little aqueduct, is sold at high prices by a
water trust at the head of which is the governor of the city.
Mecca, I am told, has only about fifty thousand inhabitants. It fills
the valley and runs up the sides of the hills. The houses are of dark
stone, built in one, two, and three stories overhanging close to the
streets. There are no pavements; it is often dusty, and one would
have to feel all the holiness of the surroundings to make life
agreeable for him in such an unattractive spot.
The most important place in Mecca is the sacred mosque and the
most important thing in the mosque is the Kaaba, a cube-shaped
stone building which stands in its centre. In the southeast corner of
this building, at about five feet from the ground, is the black
meteorite that the Mohammedans say was once a part of the Gates
of Paradise. When Adam was cast out, this stone fell with him,
dropping down near Mecca. At that time, they say, it was a beautiful
white colour, but it is now turned to jet, having been blackened by the
kisses of sinners. Every pilgrim who comes to Mecca presses his lips
to it again and again, imagining that as he does so his sins go out of
him into the stone, and his soul becomes as pure as it was when he
was a baby. There are several hundred thousand pilgrims who
perform this act every season, so that the holy stone of the Kaaba
gets its millions of kisses each year. What a load of sin it must carry!
CHAPTER XXVII
ALONG THE AFRICAN COAST

The two chief ports on the African coast of the Red Sea are Port
Sudan and Suakim. They were nothing until the completion of the
Red Sea road. The original plan was to use Suakim as the terminus
of the Sudan railway. The English surveyors, however, finding a
much better harbour at Port Sudan, extended the railroad to that
point. The town which was a mere village a few years ago has now
several thousand people, and grows like one of the mushroom
settlements of the Canadian west.
Going on southward we passed the Italian possessions on the
west coast of the Red Sea, where they have a colony known as
Eritrea. This colony begins about one hundred and fifty miles south
of Suakim and runs down almost to the Strait of Bab-el-Mandeb. It is
not wide, extending back from the coast only to where the
Abyssinian hills begin. The Italians tried to add to Eritrea a large part
of Abyssinia but failed, owing to the resistance of King Menelik. The
land they have now is of small value. There are only a few tracts that
can be irrigated, and the exports are unimportant. The strip is
inhabited by nomads, who raise camels, oxen, sheep, and goats. As
the pasturage is scanty, the shepherds have to move about from
place to place with their stock. Some of the tribes live in tents. Their
wants are simple to an extreme.
The chief Italian port is Massawa, a little town situated on a coral
island joined to the mainland by a causeway. Its two short railways,
which connect it with the Abyssinian hills, comprise about forty-eight
miles of track. One road is to be continued to the town of Asmara,
near which some gold mines have been opened.
The Italians have built a telegraph line from their port to Addis
Abbaba, the capital of Abyssinia, and they are trying to increase their
trade with that country. They are shipping considerable salt, which,
strange to say, is so relished by the Abyssinians that it brings more
than sugar and takes much the same place among them as candy
and tobacco with us. The average Abyssinian carries a stick of rock
salt with him and takes a suck of it between whiles. If he meets a
friend, he asks him to have a taste of his salt stick and his friend
brings out his individual stick and they take lick about. It is just as it
was with snuff in the days of our forefathers, when everyone offered
his friends a pinch of his choice macaboy.
Besides Eritrea Italy owns another and larger strip of East Africa.
This is Italian Somaliland, which begins at the mouth of the Gulf of
Aden and runs down to the border of the British coast possessions.
We shall pass it on our way to Mombasa. Italian Somaliland, though
about three times as large as Ohio, has a population only two thirds
that of the city of Cleveland, and is of little value. The people, who
are largely nomadic, are engaged in cattle raising and agriculture.
If you will look on the map, you will see that the Gulf of Aden
seems to rest on a shelf-like projection jutting out from the African
continent. This projection reaches into the Indian Ocean for a
distance of seven hundred and eighty miles, and is sometimes called
the “Great Horn of Africa.” It ends in Cape Guardafui, of which we
shall have a good view from our steamer as it leaves the gulf and
starts south.
The cape is a mighty bluff rising almost straight up from the blue
waters of the Indian Ocean. Its sides are of black rock, ragged and
rugged, and its top is covered with sand. There is sand at its foot and
lodged in the crevices, making yellow streaks against the black
background. Beyond the cape extend sandy hills which swell over
one another until they are lost in the distance. The country all about
is desert. Neither trees, bushes, habitations, nor animals are to be
seen. The clouds hang low over the cape, and out at sea the air is as
moist as that of Virginia in April. Seen from the ocean, the bluff
assumes the outlines of a sleeping lion with its tail in the sand. Still
farther out it looks like a fortification towering over the sea. One
hundred and thirty miles to the eastward, on the direct route to India,
is Sokotra Island, owned by the British.
We went on southward, passing British Somaliland, a country a
little larger than the State of Missouri, with a population of several
thousand Mohammedan nomads who roam about from pasture to
pasture with their cattle and camels. The colony came into the hands
of the British after the war with the Mahdi, having belonged before
that to Egypt. It was first administered by the government of India,
but it is now managed directly from London.
Fifty years ago Suez, where canal and Red Sea meet and “East of Suez”
begins, was a miserable Arab village. Now it is a city where several thousand
Europeans share the general dreariness of this hot and desolate spot.
When two ships meet, one usually stops close to the bank and lets the other
pass. In places the sides are lined with stones to prevent slides, and dredges are
at work all the time keeping the channel clear.

Back of the European colonies that fringe the coast lies Abyssinia,
one of the most interesting countries of the Black Continent. With the
exception of Liberia, it is the only one that is independent of Europe.
Recognized by the Powers as a self-governing state, it has been
able to preserve its native monarchy. Everyone in America has heard
of the famous King Menelik II, founder of the present government,
and the name is still one to conjure with in that country. It is said that
an Abyssinian can stop another from whatever he happens to be
doing by calling out to him: “Ba Menelik,” or “In the name of Menelik.”
There are penalties for using this formula frivolously, and the one so
doing may be called upon to justify his action before a judge.
The empire of Abyssinia consists of a mighty plateau ten times as
large as the State of Ohio, from which rise many high mountains.
The country might be called the roof of the continent, and has so
much beautiful scenery that it has been dubbed the African
Switzerland. The plateau consists of great tablelands rising one
above the other and cut up by great gorges and mighty canyons
somewhat like those of the Rockies. In the centre of the plateau is
Lake Tsana, and down its sides flow great rivers, some of which are
lost in the sands while others, such as the Atbara and the Blue Nile,
give food and water to Egypt. The Blue Nile has its source in Lake
Tsana.
Abyssinia has some of the best soil of Africa. It is, in fact, a fertile
island in the midst of a sea of deserts and swamps. It will grow
almost anything, including sugar and cotton in the lowlands, coffee
higher up, and still higher the hardy grains of the temperate zone.
This country is said to be the first home of the coffee plant. It has a
province called Kaffa, whence the first coffee beans were carried to
Arabia. The word “coffee” comes from the name of that province. In
Kaffa, coffee trees grow so large that they are used for timber. In
some places they grow wild. In others the coffee is cultivated.
At present Abyssinia is almost unexplored, but its opening and
development are assured, and it may become one of the tourist and
hunting resorts of the future. The land is especially interesting to us
in that most of the Abyssinians are Christians, their religion being
about the same as that of the Copts of Egypt.
CHAPTER XXVIII
ADEN

Leaving the Red Sea at the Strait of Bab-el-Mandeb, we came to


Aden, Arabia, and thence went on down along the coast of the
Indian Ocean to Mombasa. The very best of our Mocha coffee is
shipped from Aden to the United States. It comes here on camels
from the province of Yemen, where it is raised by the natives, each
family having a few bushes about its hut and producing only enough
for home use and a little for trading.
There are no big plantations and no coffee factories. When ripe
the berries are gathered and dried in the sun. After this they are put
up in bales, and carried on camelback over the hills to this place.
They are then hulled between millstones turned by hand, and
winnowed and sorted for shipment. The latter work is done by the
women, who look over each grain carefully, taking out the bad ones.
Labour is cheap, but the coffee has to go through many hands. It has
to pay toll to the chiefs of the tribes who own the country through
which it is carried, so it must be sold at high prices. For this reason
we have imitations of Mocha coffee from all parts of the world.
For many years this port of Aden has belonged to John Bull, who
took possession of it in 1839, and later got hold of the island of
Perim in the Strait of Bab-el-Mandeb also. That island is about a
hundred miles from Aden and the two places practically control the
entrance to the Red Sea and the Suez Canal. As for Aden, it is the
Gibraltar of this part of the world, as well as one of the greatest of
the British coaling stations. The harbour is excellent, and the outer
entrance is more than three miles wide. The inner waters have been
dredged so that steamers of twenty-six feet draft can go everywhere,
and there is room enough for all the vessels that pass through the
canal to anchor here at one time.
Aden is strongly fortified. The town, which stands on a volcanic
isthmus, is guarded by a broad ditch cut out of the solid rock. It has a
garrison of several thousand soldiers, guns of the latest pattern, and
no one knows how many submarine mines and other defences
against attack.
But no matter what its military importance, Aden is the sorriest city
I have ever seen. There is nothing like it except Iquique on the
nitrate coast of South America, and Iquique is a paradise compared
with Aden. Imagine a great harbour of sea-green water, the shores of
which rise almost abruptly into ragged mountains of brown rock and
white sand. There is not a blade of grass to be seen, there are no
trees, and even the cactus and sage brush of our American desert
are absent. The town is without vegetation. It is as bare as the bones
of the dead camels in the sandy waste behind it, and its tropical sun
beats down out of a cloudless African sky. Everything is gray or a
dazzling white. The houses on the sides of the hills are white, the
rocks throw back the rays of the sun, and the huts upon their sides
are of the same gray colour as themselves.
Each year thousands of Moslems from North and East Africa make the
pilgrimage to this city of Mecca. They worship at the shrines sacred to Islam, chief
among which is the Kaaba, containing the Holy Rock.
Aden is in the land of the camel, and processions of them come into the city
every day, bringing coffee and gums. Eighteen miles is a day’s journey for the
average freight animal, but those used for riding go much farther.

The city looks thirsty and dry. It is dry. There is only a well or so in
the place, and these, I am told, the English bought of their owners for
something like one million dollars. Almost all of the water used is

You might also like