Professional Documents
Culture Documents
Download Database Processing Fundamentals Design and Implementation 15th Edition Kroenke Solutions Manual all chapters
Download Database Processing Fundamentals Design and Implementation 15th Edition Kroenke Solutions Manual all chapters
Download Database Processing Fundamentals Design and Implementation 15th Edition Kroenke Solutions Manual all chapters
https://testbankfan.com/product/database-processing-fundamentals-
design-and-implementation-15th-edition-kroenke-test-bank/
https://testbankfan.com/product/database-processing-fundamentals-
design-and-implementation-13th-edition-kroenke-solutions-manual/
https://testbankfan.com/product/database-processing-fundamentals-
design-and-implementation-14th-edition-kroenke-solutions-manual/
https://testbankfan.com/product/database-processing-fundamentals-
design-and-implementation-13th-edition-kroenke-test-bank/
Database Processing Fundamentals Design and
Implementation 14th Edition Kroenke Test Bank
https://testbankfan.com/product/database-processing-fundamentals-
design-and-implementation-14th-edition-kroenke-test-bank/
https://testbankfan.com/product/database-processing-11th-edition-
kroenke-solutions-manual/
https://testbankfan.com/product/database-processing-12th-edition-
kroenke-solutions-manual/
https://testbankfan.com/product/database-processing-12th-edition-
kroenke-test-bank/
https://testbankfan.com/product/database-systems-design-
implementation-and-management-12th-edition-coronel-solutions-
manual/
INSTRUCTOR’S MANUAL
TO ACCOMPANY
Chapter 7
SQL for Database Construction and Application Processing
Prepared By
David J. Auer
Western Washington University
Instructor's Manual to accompany:
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
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
• CREATE TABLE
• ALTER TABLE
• DROP TABLE
• TRUNCATE TABLE
7.2 What does DML stand for? List the SQL DML statements.
• 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:
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 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.
Page 7-9
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing
• 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
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:
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.
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.
Page 7-11
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing
7.9 Are there any significant differences between the CUSTOMER_01 and CUSTOMER_02
tables? If so, what are they?
7.10 Write and run an SQL CREATE TABLE statement to create the CUSTOMER_03 table.
Page 7-12
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing
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.
Page 7-13
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing
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.
Page 7-14
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing
);
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
);
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.
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.
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.
Page 7-16
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing
);
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
);
7.19 In Review Question 7.18, how did you implement the ON UPDATE referential integrity
action? Why?
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.
7.23 Write and run a set of SQL INSERT statements to populate the CUSTOMER_02 table.
Do not use a bulk INSERT command.
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.
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.
/********************************************************************************/
Page 7-20
Copyright © 2019Pearson Education, Inc.
Another random document with
no related content on Scribd:
as a Natica or Buccinum perforates the shell of a Tellina or Mactra in
order to get at its contents.
Few observations appear to have been made on the habits or
food of Streptaxis, Rhytida, Ennea, Daudebardia, Paryphanta, and
other carnivorous Mollusca. A specimen of Ennea sulcata, enclosed
in the same box as a Madagascar Helix (sepulchralis Fér.) many
times its own size, completely emptied the shell of its inhabitant.[126]
Mr. E. L. Layard informs me that certain Cape Rhytida, e.g. R.
capsula Bens., R. dumeticola Bens., and R. vernicosa Kr., eat
Cyclostoma affine, Helix capensis, H. cotyledonis, etc. To Mr. Layard
I am also indebted for the—perhaps apocryphal—tradition that the
best time to capture the great Aerope caffra Fér. in numbers was
after an engagement between the Kaffirs and Zulus, when they
might be observed streaming from all points of the compass towards
the field of slaughter. The Cuban Oleacina are known to secrete a
very bitter fluid which they emit; this perhaps produces a poisoning
or benumbing effect upon their victims when seized. They devour
operculates, e.g. Helicina regina and sagraiana.[127]
CHAPTER III
ENEMIES OF THE MOLLUSCA—MEANS OF DEFENCE—MIMICRY AND
PROTECTIVE COLORATION—PARASITIC MOLLUSCA—COMMENSALISM—
VARIATION
Means of Defence
As a rule, among the Mollusca, the shell forms a passive mode of
resistance to the attacks of enemies. Bivalves are enabled, by
closing their valves, to baffle the assault of their smaller foes, and
the operculum of univalves, both marine and land, serves a similar
purpose. Many land Mollusca, especially Helix and Pupa, as well as
a number of Auriculidae, have the inside of the aperture beset with
teeth, which are sometimes so numerous and so large that it is
puzzling to understand how the animal can ever come out of its
shell, or, having come out, can ever draw itself back again. Several
striking cases of these toothed apertures are given in Fig. 24.
Whatever may be the origin of these teeth, there can be little doubt
that their extreme development must have a protective result in
opposing a barrier to the entrance, predatory or simply inquisitive, of
beetles and other insects. Sometimes, it will be noticed (G), the
aperture itself is fairly simple, but a formidable array of obstacles is
encountered a little way in. It is possible that the froth emitted by
many land snails has a similar effect in involving an irritating intruder
in a mass of sticky slime. The mucus of slugs and snails, on the
other hand, is more probably, besides its use in facilitating
locomotion, a contrivance for checking evaporation, by surrounding
the exposed parts of their bodies with a viscid medium.