Complete Download of Database Processing Fundamentals Design and Implementation 15th Edition Kroenke Solutions Manual Full Chapters in PDF
Complete Download of Database Processing Fundamentals Design and Implementation 15th Edition Kroenke Solutions Manual Full Chapters in PDF
com
https://testbankdeal.com/product/database-processing-
fundamentals-design-and-implementation-15th-edition-kroenke-
solutions-manual/
OR CLICK HERE
DOWNLOAD NOW
https://testbankdeal.com/product/database-processing-
fundamentals-design-and-implementation-15th-edition-kroenke-test-
bank/
https://testbankdeal.com/product/database-processing-
fundamentals-design-and-implementation-13th-edition-kroenke-
solutions-manual/
https://testbankdeal.com/product/database-processing-
fundamentals-design-and-implementation-14th-edition-kroenke-
solutions-manual/
https://testbankdeal.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://testbankdeal.com/product/database-processing-
fundamentals-design-and-implementation-14th-edition-kroenke-test-
bank/
https://testbankdeal.com/product/database-processing-11th-
edition-kroenke-solutions-manual/
https://testbankdeal.com/product/database-processing-12th-
edition-kroenke-solutions-manual/
https://testbankdeal.com/product/database-processing-12th-
edition-kroenke-test-bank/
https://testbankdeal.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.
Chapter Seven – SQL For Database Construction and Application Processing
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.
Page 7-21
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing
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', '[email protected]', 234.00);
INSERT INTO SALE_01 (DateOfSale, EmailAddress, SaleAmount)
VALUES('14-JAN-2018', '[email protected]', 56.50);
INSERT INTO SALE_01 (DateOfSale, EmailAddress, SaleAmount)
VALUES('16-JAN-2018', '[email protected]', 123.00);
INSERT INTO SALE_01 (DateOfSale, EmailAddress, SaleAmount)
VALUES('17-JAN-2018', '[email protected]', 34.25);
Page 7-22
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing
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.
Page 7-23
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing
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
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.
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.
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
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:
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 a PROJECT row is deleted, then all the ASSIGNMENT rows that are
connected to the deleted PROJECT row will also be deleted.
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
Page 7-30
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing
Page 7-31
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing
Page 7-32
Copyright © 2019Pearson Education, Inc.
Chapter Seven – SQL For Database Construction and Application Processing
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.
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 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.
Discovering Diverse Content Through
Random Scribd Documents
… Un pamphlétaire qui a le malheur d'employer son esprit à
dénigrer tous les lieux qui lui ont donné l'hospitalité, et qui ne mérite
pas d'être nommé dans cette enceinte, avait fait sur Rome un livre
calomnieux. A la rigueur, on comprend que, comme certaine
publication récente, celle-ci ait pu tromper pendant quelques heures
la vigilance du ministère de l'intérieur. Mais non; ce sont des jours,
ce sont des semaines qu'on lui donne; on la saisit quand l'édition
tout entière est vendue; et, quant au procès, on n'en a plus entendu
parler.
Stimulé par ce premier succès, notre pamphlétaire, dans trois
feuilletons de l'Opinion nationale, s'en prend à l'innocente ville de
province qui l'abrite pendant la belle saison et qui n'a d'autre tort
que de ne lui avoir pas encore élevé de statue, de ne lui avoir pas
même donné un siége dans son conseil municipal. Indignement
calomnié dans sa vie publique et privée, le maire n'écoute que la
voix de sa conscience et dépose une plainte en diffamation. Peu
importe que, plus tard, M. le ministre de l'intérieur le supplie ou le
somme de la retirer. Le maire n'est pas seul offensé; l'honneur de
vingt familles a été cruellement blessé; et d'ailleurs l'Alsace entière
se sent insultée dans la personne de cet infortuné maire Sauerkraut,
dont le nom seul est une insulte à notre agriculture; dans la
personne de cet infortuné sous-préfet Ignacius, en qui l'on veut sans
doute atteindre un des courageux sénateurs qui défendent le saint-
siége. (Nouvelles rumeurs.) D'ailleurs, le délit est constant; la justice
est saisie; les assignations sont données, l'audience est fixée.
L'affaire en étant là, il n'est pas de force humaine qui puisse
l'empêcher d'avoir son cours; il n'est pas de force humaine qui
puisse empêcher un tribunal saisi de se prononcer.
Au moment où l'opinion publique attendait ainsi une légitime
satisfaction, la veille même de l'audience, un bruit se répand avec la
rapidité de la foudre.
Plusieurs membres. Oh! oh!
M. Keller. De Paris est tombé tout à coup un personnage
mystérieux, muni de pouvoirs supérieurs; ce personnage demande
communication du dossier, le met dans son sac, et, à la stupeur du
tribunal, l'emporte pour l'examiner à loisir. (Réclamations sur
plusieurs bancs. Interruptions diverses.)
Quelques membres. Parlez! parlez!
M. Keller. Sans doute, on craignait la passion des juges; on
craignait peut-être l'influence occulte de la société de Saint-Vincent
de Paul.
Le fait est qu'à l'heure qu'il est, le personnage dont je parle, qui
n'est autre, dit-on, qu'un certain procureur général, conserve le
dossier et l'examine encore; et l'Alsace, attristée, blessée dans son
honneur… (Vives réclamations sur plusieurs bancs.)
M. le baron de Reinach. Parlez en votre nom! ne parlez pas au nom
de l'Alsace!
M. Keller. L'Alsace se demande si un pareil mépris de la légalité
est possible en France, et se dit que, certainement, l'empereur ne
sait pas comment on rend la justice en son nom. (Vives et
nombreuses réclamations.)
M. Rigaud. Vous attaquez la magistrature, et jamais personne ne
l'a fait en France! Elle est au-dessus de toutes les attaques, de tous
les soupçons! (Très-bien! très-bien!)
M. Keller. Messieurs, ces faits sont notoires. Ils m'ont été
confirmés de Strasbourg par les lettres les plus détaillées que je
pourrais lire à la Chambre, si je ne craignais de fatiguer son
attention; et, tant que le gouvernement ne les aura pas démentis, je
les avance comme tout à fait certains… (Rumeurs et dénégations sur
plusieurs bancs.)
M. Abatucci. Le maire a retiré sa plainte!
M. Keller. Lorsqu'un tribunal est saisi, peu importe que la plainte
soit retirée!
S. Exc. M. Baroche, ministre, président du conseil d'État. Pas en
matière de diffamation!
M. Keller. Je vous demande pardon, mais je crois que, sauf le cas
d'adultère, toutes les fois qu'un tribunal est saisi, il doit se
prononcer.
M. le Ministre. Vous êtes dans l'erreur. En matière de diffamation,
il faut que le plaignant insiste.
Du reste, nous ne savons pas un mot de tout ce que vous
racontez là (mouvement), et à ce sujet je dois faire une observation.
Quand on veut mettre en cause le gouvernement sur des faits
spéciaux, un sentiment que je ne veux pas dire, mais que la
Chambre comprendra, devrait conduire l'orateur, ainsi que cela se
fait partout, ainsi que cela se fait en Angleterre, ainsi que cela se
faisait autrefois en France, à prévenir le gouvernement, de manière
à le mettre à même de prendre des renseignements et de vérifier les
faits que l'on veut porter devant la Chambre. Le gouvernement est
ainsi en mesure de répondre aux interpellations; il peut même
prévenir ces interpellations par des explications. Il me semble que
mon observation trouve ici sa place. (Très-bien! très-bien!)
M. Keller, continuant son discours. Quelle était la cause de cet
abus de pouvoir?…
M. le Ministre. Et mon observation, il faut y répondre! Pourquoi
M. Keller ne répond-il pas?
M. Keller, continuant. Quelle était la cause de cet abus de
pouvoir, inouï dans nos annales judiciaires? Messieurs, elle est fort
simple.
Et d'abord, il eût été pénible de voir une fois de plus le ruban de
la Légion d'honneur sur les bancs de la police correctionnelle.
Et puis, chose plus grave, vous savez que, dans l'état de notre
législation sur la presse, deux condamnations suffisent pour faire
supprimer de droit le journal le plus dévoué. Il n'en faut pas tant
pour un journal ordinaire. Eh bien, l'Opinion nationale venait
précisément d'être frappée à Montpellier pour avoir diffamé le
président d'une association charitable. Une seconde condamnation,
c'était son arrêt de mort. La France allait être privée des éminents
services que lui rend ce journal. Il fallait le sauver: on l'a sauvé.
Cependant, le cas pourrait bien se reproduire. Il n'est pas dit que
les gens que les journaux insultent ne finiront pas par se lasser de
leur longanimité; il n'est pas dit que tous les tribunaux se
montreront aussi complaisants que celui que je viens de citer…
(Vives réclamations.)
Voix nombreuses. C'est intolérable! A l'ordre! à l'ordre!
S. Exc. M. Baroche, ministre, président du conseil d'État. Vous ne
pouvez pas dire qu'un tribunal s'est montré complaisant.
Permettez-moi un mot, monsieur le président…
M. Roques-Salvaza. C'est une affaire de discipline qui regarde le
président. Nous demandons le rappel à l'ordre!
M. le Président. Monsieur Keller, vous avez, à deux reprises
différentes, insulté la magistrature; vous avez porté une accusation
grave contre la magistrature et contre le gouvernement. Je vous ai
laissé continuer, parce que je croyais, en mon âme et conscience,
que le gouvernement, averti par vous, avait pu se mettre en mesure
de réfuter vos accusations. J'ai toujours pensé que, quelle que fût la
gravité d'une incrimination dirigée contre le gouvernement, le mieux
était de ne pas interrompre l'orateur, de le laisser produire en toute
liberté et jusqu'au bout ses imputations, afin de fournir au
gouvernement l'occasion de se justifier immédiatement vis-à-vis de
la Chambre et du pays.
Mais il vient d'être déclaré par M. le président du conseil d'État
qu'aucun avis ne lui avait été préalablement donné; et il s'en est
plaint à bon droit. J'insiste à cet égard sur l'observation que vient de
faire M. le président du conseil d'État. Jamais, dans aucune
assemblée parlementaire (c'est une question de loyauté, de parti à
parti, d'opposition à gouvernement), jamais on ne s'est permis de
porter une accusation sur des faits aussi ténébreux, sans prévenir le
gouvernement, afin qu'il puisse procéder à une enquête et éclaircir
les faits, de manière à se justifier devant le pays. Agir autrement, je
suis obligé de vous le dire, n'est pas loyal. (Très-bien! très-bien!)
Maintenant, je vous rappelle à l'ordre: je ne permets pas que,
dans cette enceinte, on insulte l'institution la plus respectable et la
plus désintéressée, la magistrature. (Très-bien! Bravo!) Et, si vous
continuez, je vous interdirai la parole. (Oui! oui! Très-bien!)
M. Keller. Messieurs, on vient de pourvoir à cette situation
exceptionnelle de certains journaux par une loi qui, sous prétexte
d'agrandir la liberté de la presse, achèvera, je le crains bien, de
déposséder la légalité en faveur de l'arbitraire. M. le ministre de
l'intérieur pourra toujours, du jour au lendemain, et par mesure
administrative, faire supprimer un journal; les tribunaux ne le
pourront plus. Voilà, je le crois, le véritable sens du projet que nous
n'avons fait qu'entrevoir en comité secret. Le Siècle et l'Opinion
nationale pourront continuer leur triste polémique: ils n'en seront
pas moins immortels, et, à l'heure où je vous parle, vous venez de
voir jusqu'où se permet d'aller maintenant cette audace impunie, et,
pour moi, je suis encore ému d'indignation et de dégoût par la
lecture de cet article sans nom, dans lequel on a insulté, non-
seulement les malheurs du saint-siége, mais l'honneur de notre
armée de Crimée, mais la dignité même du trône, article dans lequel
on est venu nous vanter les délices et les raffinements du
despotisme païen sous le nom de je ne sais quel fils légitime de la
révolution française. Mais que veut-on dire par là? Tenez, malgré
moi, cette insolence m'en a rappelé une autre.
«Vous seul, disait un autre pamphlétaire s'adressant à un autre
prince, vous seul, enveloppé d'une auréole d'azur et d'or, vous
sommeillez au milieu des orages; votre quiétude m'ennuie comme la
vertu d'Aristide fatiguait le paysan d'Athènes; mais non, la France
sait que, relégué à la pairie, vous subissez un ostracisme involontaire
qui vous interdit toute participation aux affaires publiques.»
C'était en 1827; ce prince qu'on outrageait par un encens non
moins coupable, mais pourtant moins grossier, c'était le duc
d'Orléans. Loin de moi, messieurs, loin de moi la pensée de faire
entre ces deux personnages le moindre rapprochement déplacé;
mais il est évident que l'intention des deux auteurs était la même. Et
quand je vois M. le ministre de l'intérieur si facile à alarmer par les
souvenirs de l'ancien Palais-Royal, je me demande s'il ne serait pas
plus prudent et plus sage d'empêcher une si compromettante
apothéose du Palais-Royal actuel. (Mouvements divers.)
En réponse à cette agression, je publiai immédiatement chez
Dentu la brochure suivante:
LETTRE A M. KELLER
Monsieur,
… Rencontre sa destinée
Souvent par les chemins qu'il prend pour l'éviter.
. . . . . . . . . . . . . . . . . . . .
Vous avez lu? Merci. Et maintenant, monsieur, faites-moi
l'honneur de me dire quelle intention j'avais, selon vous, en écrivant
ce portrait? Vous semble-t-il que j'aie voulu mettre en saillie la
supériorité du pouvoir absolu sur l'équilibre constitutionnel, ou que
j'aie cherché à émouvoir la compassion de mes lecteurs au profit
d'une cause perdue? Ai-je préparé le retour de M. Guizot aux affaires
publiques? Ai-je conseillé à l'empereur de le choisir pour ministre?
Peut-être mon intention était-elle, au contraire, de tenir les ministres
en garde contre un ambitieux de soixante et dix ans? Cet article—ce
fragment d'article—est-il un manifeste orléaniste? ou une profession
de foi bonapartiste? ou un réquisitoire indirect contre les intrigues de
l'Académie française? Rien de tout cela, monsieur. Votre bon sens
vous le dit clairement, parce que le sujet n'est pas de ceux qui
excitent les passions violentes et aveuglent la raison des partis. Vous
comprenez, sans que je vous l'explique, que cet assemblage de
détails vrais n'a pas d'autre intention, pas d'autre prétention, pas
d'autre ambition, que de représenter au vif la figure de M. Guizot
avec ses ombres et ses lumières. C'est une œuvre d'art, bonne ou
mauvaise, suivant le goût du lecteur. Placez-la, si le cœur vous en
dit, au rang des amplifications de collége, ou même à la hauteur des
tapisseries en chenille que les demoiselles exécutent dans leur
couvent, ou même au niveau de ces sculptures patientes qu'un
galérien taille à coups de canif dans une noix de coco: je ne
chicanerai point sur la qualité de l'ouvrage, pourvu que vous
reconnaissiez avec moi que ce portrait n'est qu'un portrait.
Tâchez d'être aussi juste pour celui du prince Napoléon. Étudiez-
le, nonobstant «l'indignation et le dégoût» que vous avez étalés
devant la Chambre; mais surtout étudiez-le de bonne foi, comme je
l'ai tracé. Souvenez-vous que c'est une œuvre d'art, et pas autre
chose, et ne vous amusez point à chercher des queues de serpent à
sonnette où l'auteur n'en a pas mis.
Le voici, ce portrait, non pas exactement tel que vous l'avez lu
dans l'Opinion, mais tel que je l'ai écrit et envoyé au journal [7] :
[7] Voir à la page 239.
. . . . . . . . . . . . . . . . . . . .
Je vous ai loyalement averti que ce texte n'était pas tout à fait
celui que vous avez lu dans l'Opinion. Il s'en faut de seize mots, qui
ont été ajoutés au dernier moment sur l'épreuve, et ce mode de
correction in extremis ne vous étonnera point, si vous avez quelque
notion des nécessités du journalisme et de la responsabilité des
rédacteurs en chef.
Ceci posé, dites-moi, je vous prie, si ce portrait est une
apothéose? Pas plus qu'une satire. J'ai esquissé de mon mieux les
qualités et les défauts d'un homme que je connais peu, avec qui j'ai
causé cinq ou six fois, que je n'ai pas vu face à face depuis une
année environ. C'est une peinture incomplète, si j'ai omis quelque
trait d'ombre ou de lumière: ce ne sera jamais, quoiqu'il vous ait plu
de le proclamer devant la Chambre, un tableau dégoûtant.
Reprochez-moi, si vous voulez, la témérité de ma plume; dites qu'il
ne sied pas à un homme qui n'est rien de distribuer aux grands
l'éloge et le blâme; ajoutez qu'on s'expose ainsi aux jugements les
plus faux et les plus injustes: vous avez le droit de me le dire après
me l'avoir prouvé. Où donc avez-vous vu que «j'insultais aux
malheurs du saint-siége?» J'ai rappelé le succès d'un discours
éloquent; cela n'offense que les orateurs manqués. Comment ai-je
«insulté l'honneur de notre armée de Crimée?» Exactement comme
j'ai insulté l'agriculture dans le feuilleton de Sauerkraut. Ai-je
«insulté la majesté du trône,» en disant que les uns s'assoient
dessus et les autres à côté? Est-ce «vanter les délices et les
raffinements du despotisme païen» que d'admirer sur parole une
petite maison romaine où je ne suis jamais entré, quoiqu'on m'ait
fait l'honneur de m'y inviter une fois?
Que le monde est méchant, monsieur! Je ne crains pas de m'en
ouvrir à vous, qui êtes un homme du monde. Il s'est rencontré dans
votre parti des esprits assez mal faits pour prétendre que j'attaquais
la famille d'Orléans dans ce qu'il y a de plus délicat et de plus sacré.
J'égratigne en passant la politique du vieux Palais-Royal, la plus
bâtarde que la Révolution ait portée dans ses flancs, et vos amis
affectent de trouver dans ce mot de bâtard un outrage monstrueux
contre une famille exemplaire!
Ma chère cousine,