Sei sulla pagina 1di 10

Assignment 4

DARSHIL SHAH STUDENT ID:1771687

Problem 15. (25 points) Write the business rules that are reflected in the ERD shown in Figure P2.15.
(Note that the ERD reflects some simplifying assumptions. For example, each book is written by only one
author. Also, remember that the ERD is always read from the "1" to the "M" side, regardless of the
orientation of the ERD components.)

Entities — There are four entities in the above ERD namely PUBLISHER, BOOK and

AUTHOR and CONTRACT.

Relationships — The various relationships between the entities are the following:

*PUBLISHER and BOOK :Between the PUBLISHER and BOOK entities, there is a 1: M
relationship. This is because a PUBLISHER can publish many BOOK but each BOOK must be
published by a Singe PUBLISHER.

*BOOK and AUTHOR: Between the BOOK and AUTHOR entities, there is a 1: M relationship. This
is because an AUTHOR can write many BOOK but each BOOK must be written by a single
AUTHOR.

*AUTHOR and CONTARCT :Between the AUTHOR and CONTRACT entities, there is a 1: M
relationship. This is because an AUTHOR can sign many CONTRACT but each CONTRACT must
be signed only a Single AUTHOR.

*CONTRACT and PUBLISHER: Between the CONTRACT and PUBLISHER entities, there is a 1: M
relationship.This is because a PUBLISHER can submit many CONTRACT but each CONTRACT
must be submitted by a single PUBLISHER.
Problem 16. (25 points)

Create a Crow's Foot ERD for each of the following descriptions. (Note that the word many merely
means more than one in the database modeling environment.)

a. Each of the MegaCo Corporation's divisions is composed of many departments. Each department has
many employees assigned to it, but each employee works for only one department. Each department is
managed by one employee, and each of those managers can manage only one department at a time.

b. During some period of time, a customer can download many ebooks from BooksOnline. Each of the
ebooks can be downloaded by many customers during that period of time.
d. The KwikTite Corporation operates many factories. Each factory is located in a region, and each region
can be "home" to many of KwikTite's factories. Each factory has many employees, but each employee is
employed by only one factory.

e. An employee may have earned many degrees, and each degree may have been earned by many

employees.
SQL PART
1. Modify the following SQL command so that the Rep_ID column is the PRIMARY KEY for the table and
the default value of Y is assigned to the Comm column. (The Comm column indicates whether the sales
representative earns commission.)

2. Change the STORE_REPS table so that NULL values can’t be entered in the name columns (First and
Last).
3. Change the STORE_REPS table so that only a Y or N can be entered in the Comm column.
4. Add a column named Base_salary with a datatype of NUMBER(7,2) to the STORE_REPS table. Ensure
that the amount entered is above zero.

ALTER TABLE STORE_REPS


ADD Base_salary NUMBER(7,2);

ALTER TABLE STORE_REPS


ADD CONSTRAINT STORE_REPS_Base_salary_ck CHECK (Base_salary > 0);

5. Create a table named BOOK_STORES to include the columns listed in the following chart.
6. Add a constraint to make sure the Rep_ID value entered in the BOOK_STORES table is a valid value
contained in the STORE_REPS table. The Rep_ID columns of both tables were initially created as
different datatypes. Does this cause an error when adding the constraint? Make table modifications as
needed so that you can add the required constraint.

YES, IT DOES CAUSE AN ERROR OF Ora-02267.By changing data-type of rep_id in book_stores.


7. Change the constraint created in Assignment #6 so that associated rows of the BOOK_STORES table
are deleted automatically if a row in the STORE_REPS table is deleted.
8. Create a table named REP_CONTRACTS containing the columns listed in the following chart. A
composite PRIMARY KEY constraint including the Rep_ID, Store_ID, and Quarter columns should be
assigned. In addition, FOREIGN KEY constraints should be assigned to both the Rep_ID and Store_ID
columns.

Column Name Datatype

Store_ID NUMBER(8)

Name NUMBER(5)

Quarter CHAR(3)

Rep_ID NUMBER(5)

*If The IMAGE of screenshot is not readable.Below is the manually written query.

CREATE TABLE REP_CONTRACTS(Store_ID NUMBER(8),Name NUMBER(5),Quarter char(3),Rep_ID


NUMBER (5)),CONSTRAINT Rep_contracts_cpk PRIMARY KEY(Store_ID,Quarter,Rep_ID),CONSTRAINT
Rep_Contracts_storeid_fk FOREIGN KEY (Store_ID) references book_stores (Store_ID),CONSTRAINT
REP_CONTRACTS_repid_fk FOREIGN KEY(Rep_ID) references store_reps(rep_id);
9. Produce a list of information about all existing constraints on the STORE_REPS table

10. Issue the commands to disable and then enable the CHECK constraint on the Base_salary column.