Database Assignment 01
Database Assignment 01
QUESTION NUMBER 1
PART 1 )
1. Oracle Instance:
Key Components:
Composed of:
Database Buffer Cache: Stores recently accessed data blocks.
Shared Pool: Stores shared SQL and PL/SQL code.
Large Pool: Allocates large memory chunks for specific operations.
Redo Log Buffer: Stores changes to the database before they're written to
disk.
Program Global Area (PGA):
DBWR (Database Writer): Writes dirty buffers from the SGA to data files.
LGWR (Log Writer): Writes redo log entries to the redo log files.
SMON (System Monitor): Performs recovery tasks, such as instance
recovery and media recovery.
PMON (Process Monitor): Monitors background and user processes,
restarting failed processes.
CKPT (Checkpoint): Synchronizes the database and redo log files.
2. Oracle Database:
Oracle RAC enables multiple database instances to share the same physical
database, improving performance and availability.
Key Features:
Key Features:
5. Oracle GoldenGate:
Key Features:
The Information Rule: All data must be represented as values in cells of a table.
This ensures data integrity and consistency.
The Guaranteed Access Rule: Every data item must be logically accessible by
specifying a table name, primary key value, and column name. This guarantees
data accessibility and retrieval.
Systematic Treatment of Null Values: Null values (representing missing or
unknown data) must be handled consistently and systematically. This avoids
ambiguity and ensures data accuracy.
The Active Online Catalog Rule: The database system must maintain an online
catalog (metadata) that describes the database structure, including tables, columns,
data types, and constraints. This metadata is essential for database management
and optimization.
The Comprehensive Data Sub-language Rule: The database system must support a
data sub-language that allows users to define, manipulate, and control data. This
sub-language should be comprehensive and powerful, covering data definition,
data manipulation, query, update, and security.
The View Updating Rule: If a view is theoretically updatable, the system must
allow updates through the view. This ensures data consistency and simplifies data
management.
The High-Level Insert, Update, and Delete Rule: The system must support high-
level insert, update, and delete operations on data. This simplifies data
manipulation and reduces the risk of errors.
The Physical Data Independence Rule: Changes to the physical storage structure
should not impact the logical structure of the database. This allows for flexibility
and optimization without affecting applications.
The Logical Data Independence Rule: Changes to the logical structure of the
database (e.g., adding or removing columns) should not impact applications. This
promotes data evolution and flexibility.
The Integrity Independence Rule: Integrity constraints should be defined and
enforced by the database system, not by application programs. This ensures data
consistency and reliability.
The Distribution Independence Rule: The system should be able to distribute data
across multiple sites without affecting the logical view of the data. This enables
scalability and performance optimization.
The Nonsubversion Rule: The system should not allow users to bypass the integrity
and security mechanisms of the database.
Relational Keys
Relational keys are fundamental to the structure and organization of relational databases. They
identify rows uniquely and establish relationships between tables. Here are the primary types:
1. Primary Key:
o A unique identifier for each row in a table.
o Cannot contain null values.
o Ensures data integrity by preventing duplicate records.
2. Candidate Key:
o Any column or combination of columns that can uniquely identify a row.
o A primary key is chosen from the candidate keys.
3. Super Key:
o A set of attributes that uniquely identifies a row.
o Includes all candidate keys and other non-key attributes that, when combined,
uniquely identify a row.
4. Alternate Key:
o Any candidate key that is not chosen as the primary key.
Data integrity rules ensure the accuracy, consistency, and reliability of data in a relational
database. Here are some key rules:
1. Entity Integrity:
o Ensures that each row in a table has a unique primary key value.
o Prevents duplicate records and maintains data consistency.
2. Referential Integrity:
o Maintains consistency between related tables.
o Ensures that foreign key values in one table reference valid primary key values in
another table.
Example: Consider a Orders table with a foreign key referencing the Customers table: |
OrderID (PK) | CustomerID (FK) | OrderDate | |---|---|---| | O001 | C001 | 2023-11-01 | |
O002 | C002 | 2023-11-02 |
The CustomerID in the Orders table must reference an existing CustomerID in the
Customers table.
3. Domain Integrity:
oRestricts the values that can be entered into a column to a specific domain or data
type.
o Ensures data accuracy and consistency.
4. User-Defined Integrity:
o Custom rules and constraints defined by the database administrator to enforce
specific business rules.
o These rules can be complex and tailored to specific organizational needs.
Relational algebra is a formal query language that provides a theoretical foundation for relational
databases. It consists of a set of operators that manipulate relations (tables) to retrieve specific
information.
Fundamental Operators
1. Selection (σ):
o Extracts rows from a relation based on a given condition.
o Syntax: σ_condition(relation)
o Example:
SQL
2. Projection (π):
o Selects specific columns from a relation.
o Syntax: π_attribute_list(relation)
o Example:
SQL
3. Union (∪):
o Combines two relations with identical schemas, eliminating duplicates.
o Syntax: relation1 ∪ relation2
o Example:
SQL
4. Intersection (∩):
o Returns rows that exist in both relations.
o Syntax: relation1 ∩ relation2
o Example:
SQL
SQL
SQL
Join Operators
Joins combine rows from two or more relations based on a related attribute.
2. Equijoin (=):
o A specific type of theta join where the comparison operator is equality (=).
o Syntax: relation1 = relation2
o Example:
SQL
SQL
4. Outer Join:
o Preserves rows from one relation even if there's no matching row in the other.
o Types:
▪ Left Outer Join (⟕): Preserves all rows from the left relation.
▪ Right Outer Join (⟖): Preserves all rows from the right relation.
▪ Full Outer Join (⟗): Preserves all rows from both relations.
Group and analytical functions are powerful tools in SQL that allow you to aggregate and
analyze data in various ways.
Group Functions
Group functions operate on a set of rows and return a single value. They are commonly used
with the GROUP BY clause to categorize data into groups.
SQL
SQL
SQL
SQL
SQL
Analytical Functions
Analytical functions operate on a set of rows and return a value for each row, based on
calculations across a set of rows. They are often used to compare values within a group or across
groups.
Common Analytical Functions:
SQL
SQL
SQL
SELECT
ProductID,
SalesAmount,
OrderDate,
RANK() OVER (PARTITION BY ProductID ORDER BY SalesAmount DESC) AS
ProductRank,
LAG(SalesAmount) OVER (PARTITION BY ProductID ORDER BY OrderDate) AS
PreviousSales
FROM
Sales;
This query will rank products by their sales amount within each product category and show the
previous sales amount for each product.
QUESTION NUMBER 2 :
Entity Classes:
• Patient
o PatientID (PK)
o Name
o DateOfBirth
o ContactDetails
o InsuranceInformation
• Appointment
o AppointmentID (PK)
o Date
o Time
o Purpose
o HealthcareProfessionalID (FK)
• HealthcareProfessional
o HealthcareProfessionalID (PK)
o Name
o Specialization
o DepartmentID (FK)
• Department
o DepartmentID (PK)
o Name
• MedicalRecord
o MedicalRecordID (PK)
o PatientID (FK)
• MedicalRecordEntry
o EntryID (PK)
o MedicalRecordID (FK)
o Date
o Description
o HealthcareProfessionalID (FK)
• Bill
o BillID (PK)
o Date
o TotalAmount
o PatientID (FK)
• InsuranceClaim
o ClaimID (PK)
o BillID (FK)
o InsuranceProvider
o ClaimStatus
• Medication
o MedicationID (PK)
o Name
o Dosage
o PrescriptionDate
• LabTest
o TestID (PK)
o TestName
o OrderDate
• TestResult
o ResultID (PK)
o TestID (FK)
o ResultDate
o ResultValue
• EmergencyCase
o CaseID (PK)
o PatientID (FK)
o AdmissionDate
o EmergencyLevel
Additional Considerations:
1. Employee
8. Daily_Special
Employee - Role: An employee can have one role, and a role can be assigned to
many employees.
Product - Supplier: A product can be supplied by one or more suppliers, and a
supplier can supply many products.
Invoice - Product: An invoice can contain many products, and a product can be part
of many invoices.
Customer - Invoice: A customer can generate many invoices, and an invoice is
generated for one customer.
Inventory - Supplier: An inventory item is supplied by one supplier, and a supplier
can supply many inventory items.
Product - Coffee_Variety: A product (coffee) can have many varieties, and a coffee
variety belongs to one product.
Invoice - Daily_Special: An invoice can include one or more daily specials, and a
daily special can be part of many invoices.
c) Connectivity for Each Relationship:
Many-to-One
Many-to-Many
Many-to-Many
One-to-Many
Many-to-One
One-to-Many
Many-to-Many
d) Relationship Names:
Has_Role
Supplied_By
Contains
Generates
Supplied_By
Is_Variety_Of
Includes
QUESTION NUMBER 2 PART C
Entity Classes and Attributes:
1. Event
4. Supplier
5. Attendee
6. Ticket
7. Feedback
8. Sponsor
9. Marketing_Campaign
Event - Event_Planner: Many-to-Many (An event can have multiple planners, and
a planner can work on multiple events.)
Event - Venue: Many-to-Many (An event can be held at multiple venues, and a
venue can host multiple events.)
Event - Supplier: Many-to-Many (An event can involve multiple suppliers, and a
supplier can provide services for multiple events.)
Event - Attendee: Many-to-Many (An attendee can attend multiple events, and an
event can have multiple attendees.)
Event - Ticket: One-to-Many (An event can have many tickets, and a ticket is
associated with one event.)
Event - Feedback: One-to-Many (An event can receive many feedback, and a
feedback is associated with one event.)
Event - Sponsor: Many-to-Many (An event can have multiple sponsors, and a
sponsor can sponsor multiple events.)
Event - Marketing_Campaign: Many-to-Many (A marketing campaign can target
multiple events, and an event can be promoted by multiple campaigns.)
Relationship Names:
Is_Planned_By
Is_Held_At
Involves
Attends
Has_Ticket
Receives_Feedback
Is_Sponsored_By
Is_Promoted_By
Entities:
Author:
Reviewer:
Review:
User:
Song:
Review:
Listening_History:
Subscription_Plan:
User - Playlist: One-to-Many (A user can have many playlists, but a playlist
belongs to one user.) Owns
Playlist - Song: Many-to-Many (A playlist can contain many songs, and a song can
be in many playlists.) Contains
Album - Song: One-to-Many (An album contains many songs, but a song belongs
to one album.) Contains
Artist - Album: One-to-Many (An artist can release many albums, but an album is
released by one artist.) Releases
Song - Genre: Many-to-Many (A song can belong to multiple genres, and a genre
can have many songs.) Belongs_To
User - Review: One-to-Many (A user can write many reviews, but a review is
written by one user.) Writes
Song - Review: One-to-Many (A song can receive many reviews, but a review is
for one song.) Receives
User - Listening_History: One-to-Many (A user can have many listening history
entries, but a listening history entry is for one user.) Has
Song - Listening_History: Many-to-Many (A song can be listened to by many
users, and a user can listen to many songs.) Is_Listened_To
User - Subscription_Plan: One-to-One (A user can have one subscription plan, and
a subscription plan can be assigned to one user.) Subscribes_To
QUESTION NUMBER 2 PART 6
Entities:
1. Vehicle:
o VehicleID (PK)
o VehicleType
o LicensePlate
o OdometerReading
2. Department:
o DepartmentID (PK)
o DepartmentName
3. Faculty:
o FacultyID (PK)
o Name
o DepartmentID (FK)
4. Reservation:
o ReservationID (PK)
o DepartmentID (FK)
o FacultyID (FK)
o VehicleID (FK)
o ExpectedDepartureDate
o Destination
5. TripCompletionForm:
o TripCompletionFormID (PK)
o ReservationID (FK)
o StartOdometerReading
o EndOdometerReading
o MaintenanceComplaints
o FuelPurchased
o CreditCardNumber
6. MaintenanceLog:
o MaintenanceLogID (PK)
o VehicleID (FK)
o Description
o InitialLogDate
o CompletionDate
o MechanicID (FK)
7. MaintenanceDetail:
o MaintenanceDetailID (PK)
o MaintenanceLogID (FK)
o MaintenanceItem
o PartUsed
o MechanicID (FK)
8. Part:
o PartID (PK)
o PartName
o MinimumQuantity
9. Mechanic:
o MechanicID (PK)
o Name
o Authorization
1. Department - Faculty: One-to-Many (One department can have many faculty members, but a
faculty member belongs to only one department.)
2. Department - Reservation: One-to-Many (One department can make many reservations, but a
reservation is made by one department.)
3. Faculty - Reservation: One-to-Many (One faculty member can make many reservations, but a
reservation is made by one faculty member.)
4. Vehicle - Reservation: One-to-Many (One vehicle can be reserved for many trips, but a
reservation is for one specific vehicle.)
5. Reservation - TripCompletionForm: One-to-One (One reservation leads to one trip completion
form, and one trip completion form is associated with one reservation.)
6. Vehicle - MaintenanceLog: One-to-Many (One vehicle can have many maintenance logs, but a
maintenance log is for one specific vehicle.)
7. MaintenanceLog - MaintenanceDetail: One-to-Many (One maintenance log can have many
maintenance details, but a maintenance detail is associated with one maintenance log.)
8. Mechanic - MaintenanceLog: Many-to-Many (Many mechanics can work on one maintenance
log, and one mechanic can work on many maintenance logs.)
9. Mechanic - MaintenanceDetail: Many-to-Many (Many mechanics can work on one maintenance
detail, and one mechanic can work on many maintenance details.)
10. Part - MaintenanceDetail: Many-to-Many (Many parts can be used in one maintenance detail,
and one part can be used in many maintenance details.)