database design

profileherb252
PROJECTfall2023-4.docx

PROJECT PART 1 (50 Pts)

In this part, you are required to write the business rules, relationships and draw an Entity-Relationship diagram (ERD) that describes the following business environment below.

Carnival Cruise Line has several ships and a variety of cruise itineraries, each involving several ports-of-call. The company wants to maintain information on the sailors who currently work on each of its ships. It also wants to keep track of both its past and future cruises and of the passengers who sailed on the former and are booked on the latter.

Each ship has at least one and, of course, normally many sailors on it. The unique identifier of each ship is its ship number. Other ship attributes include ship name, weight, year built, and passenger capacity. Each sailor has a unique sailor identification number, as well as a name, date-of-birth, and nationality. Some of the sailors are in supervisory positions, supervising several other sailors. Each sailor reports to just one supervisor. A cruise is identified by a unique cruise serial number. Other cruise descriptors include a sailing date, a return date, and a departure port (which is also the cruise’s ending point.) Clearly, a cruise involves exactly one ship; over time a ship sails on many cruises, but there is a requirement to be able to list a new ship that has not as yet sailed on any cruises, at all. Each cruise stops at least one and usually several ports-of-call, each of which is normally host to many cruises, over time. In addition, the company wants to maintain information about ports that it has not as yet used in its cruises but may use in the future. A port is identified by its name and the country that it is in. Other information about a port includes its population,whether a passport is required for the passengers to disembark there, and its current docking fee, which is assumed to be the same for all ships. Passenger information includes a unique passenger number, name, home address, nationality, and date-of-birth. A cruise typically has many passengers on it (certainly at least one). Hoping for return business, the company assumes that each passenger may have sailed on several of its cruises (and/or may be booked for a future cruise.) For a person to be of interest to the company, he or she must have sailed on or be booked on at least one of the company’s cruises. The company wants to keep track of how much money each passenger paid for (or will pay for) each of their cruises, as well as their satisfaction rating of the cruise, if it has been completed.

Checklist:

· Business rules- Only passengers who have sailed on or are booked for one of the company's cruises are of interest to the company. The company also keeps track of passenger satisfaction ratings for completed cruises. The company tracks the amount of money each passenger paid for (or will pay for) each cruise they have been on or booked for. Passengers may have sailed on multiple cruises and can be booked for future cruises. Passengers are identified by a unique passenger number and have attributes such as name, home address, nationality, and date-of-birth. Each cruise includes one or more ports-of-call, each identified by its name and the country it is in. Ports may have attributes like population, passport requirements, and docking fees. A cruise is uniquely identified by a cruise serial number and has descriptors like sailing date, return date, and departure port. Each cruise is associated with exactly one ship. Each sailor has a unique sailor identification number and attributes including name, date-of-birth, and nationality. Some sailors hold supervisory positions and report to a single supervisor. Each ship is uniquely identified by a ship number and has attributes such as ship name, weight, year built, and passenger capacity. Carnival Cruise Line maintains information about its ships, sailors, cruises, ports-of-call, and passengers.

Entities normalized to 3NF

Ship:

· Ship Number (Primary Key)

· Ship Name

· Weight

· Year Built

· Passenger Capacity

Sailor:

· Sailor Identification Number (Primary Key)

· Name

· Date of Birth

· Nationality

· Supervisor Identification Number (Foreign Key referring to Sailor Identification Number)

Cruise:

· Cruise Serial Number (Primary Key)

· Sailing Date

· Return Date

· Departure Port (Foreign Key referring to Port Name)

· Ship Number (Foreign Key referring to Ship Number)

Port:

· Port Name (Primary Key)

· Country(

· Population

· Passport Required

· Docking Fee

Passenger:

· Passenger Number (Primary Key)

· Name

· Home Address

· Nationality

· Date of Birth

CruisePassenger (Associative Entity to represent the many-to-many relationship between Passengers and Cruises):

· Cruise Serial Number (Foreign Key referring to Cruise Serial Number)

· Passenger Number (Foreign Key referring to Passenger Number)

· Payment Amount

· Satisfaction Rating

· Relationships 1:1, 1:M or M:N (make sure to resolve any M:N relationship)

Ship:

· Ship (1) to Sailor (M)

Sailor:

· Sailor (1) to Sailor (1) (Self-Referencing)

Cruise:

· Ship (1) to Cruise (M)

· Cruise (M) to Port (M)

Passager:

· Passenger (M) to Cruise (M)

· ALL attributes mentioned in the scenario included

Ships, Sailors, Cruises, Ports-of-call, and passenger

· Relationship participation i.e. optional, mandatory relationships.

Ship-Sailor

Sailor-Supervisor

Cruise-Ship

Cruise-Passenger

Passenger-Cruise

Passenger-Satisfaction

Cruise-Port-of-Call

Port-of-Call-Passport

Port-of-Call-Docking

Port-of-Call-Population

Cruise-Port

· Suitable names for the relationships (verbs)

Sails On

Works On

Supervises

Reports To

Stops At

Uses Port

Books On

Sailed On

Pays For

Satisfaction Rating

Has sailed on

· ERD modeled using Barker's Notation using your Oracle SQL Developer Data Modeler tool.

Entities:

Ship

· Ship Number (Primary Key)

· Ship Name

· Weight

· Year Built

· Passenger Capacity

Sailor

· Sailor ID (Primary Key)

· Name

· Date of Birth

· Nationality

· Supervisor ID (Foreign Key, refers to Sailor ID)

Cruise

· Cruise Serial Number (Primary Key)

· Ship Number (Foreign key)

· Sailing Date

· Return Date

· Departure Port (Foreign Key, refers to Port Name)

Port

· Port Name (Primary Key)

· Country

· Population

· Passport Required

· Docking Fee

Passenger

· Passenger Number (Primary Key)

· Name

· Home Address

· Nationality

· Date of Birth

Cruise-Passenger

· Cruise Serial Number (Foreign Key, refers to Cruise Serial Number)

· Passenger Number (Foreign Key, refers to Passenger Number)

· Amount Paid

· Satisfaction Rating

Cruise-Port

· Cruise Serial Number (Foreign Key, refers to Cruise Serial Number)

· Port Name (Primary Key)

· Port Country (Primary Key)

Cruise-Passenger

· Cruise Serial Number (Primary Key)

· Passenger Number(Primary Key)

Relationships:

· Sailors work on Ships:

· Many-to-One relationship from Sailor to Ship (Each Sailor is associated with one Ship).

· This relationship is represented by the "Supervisor ID" attribute in the Sailor entity.

· Ships are assigned to Cruises:

· Many-to-One relationship from Ship to Cruise (Each Ship can be assigned to multiple Cruises).

· This relationship is represented by the "Cruise Serial Number" attribute in the Ship entity.

· Cruises stop at Ports:

· Many-to-Many relationship between Cruise and Port (Each Cruise can stop at multiple Ports, and each Port can be visited by multiple Cruises).

· This relationship is represented by a separate associative entity.

· Ports can be used in Future Cruises:

· Many-to-Many relationship between Port and Cruise (Each Port can be used in multiple Cruises, and each Cruise can visit multiple Ports).

· This relationship is represented by a separate associative entity.

· Passengers are associated with Cruises:

· Many-to-Many relationship between Passenger and Cruise (Each Passenger can be associated with multiple Cruises, and each Cruise can have multiple Passengers).

· This relationship is represented by the Cruise Passenger associative entity, which includes attributes like "Amount Paid" and "Satisfaction Rating."

· Relationship strength - strong and weak entities

Strong Entities:

· Ship

· Sailor

· Cruise

· Unary and ternary relationships

Sailors and Ships-unary

Supervision-Ternary

· The Primary Keys and Foreign Key(s)

· Ship Number (Primary Key)

· Sailor ID (Primary Key)

· Supervisor ID (Foreign Key, refers to Sailor ID)

· Cruise Serial Number (Primary Key)

· Departure Port (Foreign Key, refers to Port Name)

· Port Name (Primary Key)

· Passenger Number (Primary Key)

· Cruise Serial Number (Foreign Key, refers to Cruise Serial Number)

· Passenger Number (Foreign Key, refers to Passenger Number)

· Extra: Demonstrate your knowledge of inheritance (IS-A) relationships by including entity supertypes and subtypes where appropriate

Person (Supertype)

Ship (Supertype)

Cruise (Supertype)

Port (Supertype)

Sailor (Subtype of Person)

Inherited Attributes: Unique ID, Name, Date of Birth, Nationality

Passenger (Subtype of Person)

Inherited Attributes: Unique ID, Name, Date of Birth, Nationality

Supervisor (Subtype of Sailor)

Inherited Attributes: Unique ID, Name, Date of Birth, Nationality

Cruise (Subtype of Cruise)

inherited Attributes: Cruise Serial Number, Sailing Date, Return Date, Departure Port

Port (Subtype of Port)

Inherited Attributes: Name, Country, Population, Passport Requirement, Docking Fee

Future Port (Subtype of Port)

Inherited Attributes: Name, Country, Population, Passport Requirement, Docking Fee

PROJECT PART 2

Create the database - write the SQL statements (DDL & Inserting Data) (25 pts)

Use http://apex.oracle.com to create an Oracle database according to the ERD you have created in project part1.

Checklist:

· DDL statements to create/ drop the database tables.

· Suitable data type for each field

· Constraints (PK, FK, NOT NULL, CHECK and UNIQUE) were appropriate

· Populate the database tables with a reasonable number of insert records.

· Submit the script

SQL statements (Queries) (25 Pts)

Write a minimum of 15 different queries following guidelines below:

Checklist:

• Write questions that the query should answer.

• Write an SQL statement to answer the question.

• Must demonstrate the use of the following:

1. Arithmetic Operators

Retrieve the total number of passengers.

SELECT COUNT(*) AS total_passengers

FROM PASSENGER;

A screenshot of a computer  Description automatically generated

2. Distinct

List distinct nationalities of sailors.

SELECT DISTINCT nationality

FROM SAILOR;

A screenshot of a computer  Description automatically generated

3. Concatenation

Concatenate sailor names and nationalities.

SELECT name || ' - ' || nationality AS sailor_info

FROM SAILOR;

A screenshot of a computer  Description automatically generated

4. Comparison operators.

Find passengers born between '1980-01-01' and '1990-12-31'.

SELECT *

FROM PASSENGER

WHERE date_of_birth BETWEEN TO_DATE('1980-01-01', 'YYYY-MM-DD') AND TO_DATE('1990-12-31', 'YYYY-MM-DD');

A screenshot of a computer  Description automatically generated

5. BETWEEN … AND

Find sailors born between '1980-01-01' and '1990-12-31'.

SELECT *

FROM SAILOR

WHERE date_of_birth BETWEEN TO_DATE('1980-01-01', 'YYYY-MM-DD') AND TO_DATE('1990-12-31', 'YYYY-MM-DD');

A screenshot of a computer  Description automatically generated

6. AND

7. OR

List sailors who are British OR born after '1995-01-01'.

SELECT *

FROM SAILOR

WHERE nationality = 'British' OR date_of_birth > TO_DATE('1995-01-01', 'YYYY-MM-DD');

A screenshot of a computer  Description automatically generated

8. NOT

Find sailors who are NOT American.

SELECT *

FROM SAILOR

WHERE nationality <> 'American';

A screenshot of a computer  Description automatically generated

8. IN

SELECT *

FROM SAILOR

WHERE supervisor_id IN (1, 2, 3);

9. LIKE

SELECT *

FROM SAILOR

WHERE name LIKE 'J%';

A screenshot of a computer  Description automatically generated

10. Multi table JOIN

SELECT SAILOR.name, SAILOR.nationality, SHIP.ship_name

FROM SAILOR

JOIN SAILOR_SHIP ON SAILOR.sailor_id = SAILOR_SHIP.sailor_id

JOIN SHIP ON SAILOR_SHIP.ship_number = SHIP.ship_number;

11. SORT

SELECT *

FROM CRUISE

ORDER BY sailing_date; A screenshot of a computer  Description automatically generated

12. Arithmetic functions (SUM, COUNT, AVG, MIN, MAX etc)

SELECT AVG(payment_amount) AS average_payment

FROM CRUISE_PASSENGER;

A screenshot of a computer  Description automatically generated

SELECT MIN(satisfaction_rating) AS min_rating, MAX(satisfaction_rating) AS max_rating

FROM CRUISE_PASSENGER;

A screenshot of a computer  Description automatically generated

· Provide screen captures as evidence of completing the tasks

image5.jpeg

image6.jpeg

image7.jpeg

image8.jpeg

image9.jpeg

image10.jpeg

image1.jpeg

image2.jpeg

image3.png

image4.png