BCS 221-1
BCS 221-1
2. Define Relationships:
• One-to-many: A customer can have many training sessions, but a training session
can have many customers.
• One-to-many: An instructor can teach many training sessions, but a training session
can only have one instructor.
• Many-to-many: A customer can attend many facilities, and a facility can be used by
many customers.
• Visualize the entities and their relationships using an ER diagram. This helps in
understanding the structure of the database.
• Ensure that the data is in a normalized form to avoid redundancy and inconsistencies.
This typically involves breaking down large tables into smaller, more manageable
ones.
• Select a suitable DBMS based on the size and complexity of the database,
performance requirements, and cost. Examples include MySQL, PostgreSQL, Oracle,
and Microsoft SQL Server.
• Translate the ER diagram into database tables, defining the columns (attributes) for
each table and their data types.
• Insert relevant data into the tables. This may involve importing data from existing
systems or manually entering it.
• Thoroughly test the database to ensure it functions as expected and identify any
performance bottlenecks. Optimize the database as needed to improve query
performance.
2. How are database structures at each of the three levels specified in most database
management systems.
Solution
In most database management systems (DBMS), the database structures are specified at three
levels: the internal (physical), conceptual (logical), and external (view) levels. This three-
level architecture is often referred to as the ANSI/SPARC architecture.
1. Internal Level (Physical Level):
o Description: This is the lowest level of the database architecture. It describes
how the data is physically stored in the database.
o Details: It includes the storage structures, file organization, indexing, and
access methods. This level is concerned with the efficiency of data storage and
retrieval.
o Example: Data might be stored in files on a disk, with specific indexing
mechanisms to speed up access.
2. Conceptual Level (Logical Level):
o Description: This is the middle level of the database architecture. It describes
what data is stored in the database and the relationships among those data.
o Details: It includes the logical structure of the entire database as seen by the
DBA (Database Administrator). This level abstracts away the physical details
and focuses on the logical relationships between data entities.
o Example: An ER (Entity-Relationship) diagram that shows entities like
Customer, Trainer, and TrainingSession, and their relationships.
3. External Level (View Level):
o Description: This is the highest level of the database architecture. It describes
how the data is viewed by individual users.
o Details: It includes multiple user views, each tailored to the needs of different
users or user groups. This level ensures that users can interact with the
database without needing to know the underlying complexities.
o Example: A customer might see a view that includes their personal
information and training schedule, while a trainer might see a view that
includes all their assigned training sessions and customer details.
• The physical level implements the conceptual level, and the conceptual level provides
a foundation for the external level.
• Changes at the external level can affect the conceptual level, but changes at the
conceptual level typically require changes at the physical level.
• The DBMS is responsible for managing the mapping between these levels, ensuring
that data is stored, retrieved, and presented consistently.
3. In your opinion, with reasons explain why an organization would want to embrace
the use of database systems.
Solution
Database systems are essential tools for organizations of all sizes, providing numerous
benefits that can significantly improve efficiency, decision-making, and overall operations.
Here are some key reasons why an organization would want to embrace the use of database
systems:
• Automation: Database systems can automate repetitive tasks, reducing manual effort
and increasing efficiency.
• Integration: They can integrate with other systems and applications, streamlining
workflows and eliminating data silos.
• Scalability: Database systems can scale to accommodate growing data volumes and
user demands, ensuring business continuity.
4. Cost Reduction:
• Reduced Costs: By automating tasks and improving efficiency, database systems can
help organizations reduce operational costs.
• Data Consolidation: They can consolidate data from multiple sources, reducing the
need for redundant data storage and management.
• Return on Investment (ROI): The benefits of database systems often outweigh the
initial investment, providing a positive ROI.
5. Competitive Advantage:
In conclusion, database systems are indispensable tools for organizations that want to manage
data effectively, make informed decisions, improve efficiency, and gain a competitive
advantage in today's data-driven world.
Data integrity in a database refers to the accuracy, consistency, and reliability of the data
stored within it. When multiple users access the database concurrently, there's a risk of data
inconsistencies due to conflicting updates or deletions. To maintain data integrity in such
scenarios, database systems employ various techniques:
1. Locking: This involves preventing multiple users from accessing the same data
simultaneously.
o Pessimistic Locking: A lock is acquired before a transaction starts, preventing
other users from modifying the data.
o Optimistic Locking: Transactions are executed without locks, and a check is
performed before committing changes to ensure no conflicts have occurred.
2. Timestamping: Each transaction is assigned a timestamp, and the DBMS ensures that
transactions are executed in the order of their timestamps. This helps prevent conflicts
and ensures that updates are applied in the correct sequence.
3. Versioning: Multiple versions of the same data may be maintained, allowing users to
work on different versions without interfering with each other. When conflicts arise,
the DBMS can merge or reconcile the changes.
4. Dependency Tracking: The DBMS tracks dependencies between data items, allowing
it to identify and resolve conflicts automatically. For example, if a user updates a
parent record, the DBMS can automatically update any child records that depend on it.
5. Transaction Isolation:
Example: If a user transfers money from one account to another, the transaction
ensures that both the debit and credit operations are completed. If one operation fails, the
entire transaction is rolled back, maintaining data integrity.
The DBMS ensures that transactions are isolated from each other, preventing them from
interfering with each other's operations. This helps maintain data integrity and consistency.
6. Concurrency Control:
7. Isolation Levels:
o Description: Isolation levels define the degree to which the operations in one
transaction are isolated from those in other transactions. Higher isolation
levels reduce the chances of conflicts but may impact performance.
o Example: The “Serializable” isolation level ensures that transactions are
completely isolated from each other, preventing issues like dirty reads, non-
repeatable reads, and phantom reads.
By using these techniques, database systems can effectively manage concurrent access and
ensure that data remains accurate, consistent, and reliable, even when multiple users are
working on the same data simultaneously.
6. Explain the difference between logical and physical data independence.
Solution
Logical data independence refers to the ability to change the logical structure of the data
(e.g., adding or removing attributes, changing relationships) without affecting the
applications that use the data. This is achieved by defining a conceptual schema that
represents the logical view of the data, and then mapping this schema to the physical schema,
which defines how the data is actually stored.
Physical data independence refers to the ability to change the physical storage of the data
(e.g., changing the storage format, indexing strategy, or physical location) without affecting
the logical view of the data. This is achieved by isolating the physical schema from the
conceptual schema, so that changes to the physical storage do not impact the applications that
use the data.
In summary:
• Logical data independence allows changes to the logical structure of the data
without affecting applications.
• Physical data independence allows changes to the physical storage of the data
without affecting applications.
7. We can convert any weak entity set to a strong entity set by simply adding
appropriate attributes. Why then do we have weak entities?
Solution
1. Semantic Clarity: Weak entities often represent a clear conceptual relationship with
a strong entity. For example, an "order item" is clearly dependent on an "order."
Modeling this as a weak entity emphasizes this relationship and improves the overall
understanding of the data model.
2. Data Integrity: Using weak entities can help enforce data integrity constraints. For
instance, if an order is deleted, all associated order items can be automatically deleted,
ensuring that the data remains consistent.
3. Performance Optimization: In certain scenarios, using weak entities can optimize
query performance. For example, if an order item is frequently accessed along with its
corresponding order, storing them together in a single table (as a weak entity) can
reduce the number of joins required for queries.
4. Normalization: Weak entities often contribute to a more normalized database design,
which can improve data redundancy and consistency.
5. Flexibility: Weak entities can provide flexibility in data modeling. If the relationship
between the weak and strong entity changes over time, it may be easier to modify the
weak entity rather than restructuring the entire data model.
In conclusion, while it's technically possible to convert weak entities into strong entities,
doing so may compromise the semantic clarity, data integrity, performance, or flexibility of
the database design. Therefore, weak entities remain a valuable tool in database modeling,
providing a way to represent complex relationships and enforce data constraints in a clear and
efficient manner.
Without the specific SQL query, we can infer the following based on the result set:
To return all records from the table without any conditions, we can use a
simple SELECT statement:
This query will return all rows from the Student table, regardless of the age.
(b) Modify this query so that only the login column is included in the answer.
Only login is included in the answer:
Solution
This query will return only the login column for students under 18.
(c) If the clause WHERE S.gpa>=2 is added to the original query, what is the set of
tuples in the answer, and why?
Solution
The resulting query would be:
The set of tuples in the answer would be empty because there are no students in the given
result set that meet both conditions: age < 18 and gpa >= 2.
(d) Write a query that will return the highest GPA without using ORDERBY or LIMIT
Solution
This query will return the maximum value of the gpa column in the Student table.
9. Use the following table to answer questions that follow
WORK.RECORD
Emp EmpName Project Project Dept. Dept. Grade Grade Start
No No. Name No, Loc. No Tittle Date
4321 Omondi PA2.32 Alpha DA32 KSM GR1 Grinder 24/7/07
GR2 Grinder 24/7/09
3987 Lucy PA2.32 Alpha DA56 NKR GR1 Grinder 24/7/07
GR3 Grinder 24/7/09
1. Data Integrity: Functional dependencies help ensure that the data is accurate and
consistent by defining clear relationships between attributes.
2. Elimination of Redundancy: They help identify and eliminate redundant data, which
reduces storage costs and improves database efficiency.
3. Simplified Queries: By organizing data into well-structured tables, functional
dependencies make it easier to write and maintain queries.
4. Avoidance of Anomalies: They help prevent update, insertion, and deletion
anomalies, ensuring that the database remains reliable and consistent.
(d). Give TWO reasons why the WORKRECORD table is not in third normal form.
Solution
1. Emp No → EmpName
2. Project No → Project Name
3. Dept. No → Dept. Loc
4. Grade No → Grade Title
5. Emp No, Project No, Grade No → Start Date
10. Explain the benefits of using ER data modelling techniques to assist in the design of
a relational database.
Solution
4. Facilitated Communication:
6. Scalability:
11. MMUST database needs to store information about employees (identified by PFNO.,
with salary and phone as attributes), departments (identified by dno, with dname and
budget as attributes), and children of employees (with name and age as attributes).
Employees work in departments; each department is managed by an employee; a child
must be identified uniquely by name when the parent (who is an employee; assume that
only one parent works for MMUST) is known. We are not interested in information
about a child once the parent leaves MMUST. Draw an ER diagram that captures this
information.
Solution
1. Employee
- PFNO (Primary Key)
- Salary
- Phone
2. Department
- DNO (Primary Key)
- Dname
- Budget
3. Child
- Name (Primary Key, but unique per parent)
- Age
- (FK: PFNO from Employee)
▎Relationships:
1. Works In:
- An Employee works in a Department.
- Relationship: One-to-Many (1 Department can have many Employees, but each Employee
works in one Department).
2. Manages:
- An Employee manages a Department.
- Relationship: One-to-One (1 Employee manages 1 Department).
3. Has Child:
- An Employee has Children.
- Relationship: One-to-Many (1 Employee can have many Children, but each Child is
associated with one Employee).
12. Imagine that you have been assigned to a team that will be developing an inventory
tracking system. As part of the project startup, your manager has asked each team
leader to bring a basic work plan to the next meeting. At that meeting, these workplans
will be analysed to determine the overall project timeframe, costs, personal
requirements and software requirements. For now, as the team leader for the data
design team, you have been asked to bring a work plan that identifies the phases of data
design and includes the following information for each phase:
Solution
• Description: This phase involves collecting and analyzing the requirements for the
inventory tracking system. This includes understanding the specific needs of the
users, the types of data that will be stored, and the operations that will be performed
on the data.
• Inputs: User interviews, existing system documentation, business processes, and
functional specifications.
• Outputs: Detailed requirements document, data dictionary, and initial entity-
relationship (ER) diagrams.
• Key Issue: Ensuring that the requirements are complete, accurate, and aligned with
the overall project goals.
• Anticipated Challenge: Gathering and consolidating requirements from multiple
stakeholders with varying perspectives and priorities.
• Description: This phase involves translating the conceptual model into a logical data
model, which defines the database tables, columns, and relationships.
• Inputs: Refined ER diagrams, data flow diagrams, and entity-relationship attribute
diagrams.
• Outputs: Logical data model, normalized tables, and data type definitions.
• Key Issue: Ensuring that the logical data model is normalized and optimized for
performance.
• Anticipated Challenge: Handling complex relationships and data dependencies.
• Description: This phase involves validating the data model against the requirements
and testing the database to ensure it meets the specified performance and functionality
criteria.
• Inputs: Logical data model, physical database design, test data.
• Outputs: Validated data model, test results, and recommendations for improvements.
• Key Issue: Ensuring that the data model is accurate, complete, and meets the business
needs.
• Anticipated Challenge: Developing comprehensive test cases to cover all possible
scenarios.
This work plan provides a framework for the data design team to effectively plan and execute
the data design process. By addressing these phases and key issues, the team can ensure that
the database system meets the project requirements and is well-designed for performance and
maintainability.
13. Ebebewa K Ltd prides itself on having up-to-date information on the processing and
current location of each shipped item. To do this, Ebebewa K Ltd relies on a company-
wide information system. Shipped items are at the heart of Ebebewa K Ltd product
tracking information system. Shipped items can be characterized by item
number(unique) , weight, dimensions, insurance amount, destination and final delivery
date. Shipped items are received into the Ebebewa K Ltd systems at a single retail
center. Retail centers are characterized by their type, uniqueID and address. Shipped
items make their way to their destination via one or more standard Ebebewa K Ltd
transportation events (i.e., flights, truck deliveries). These transportation events are
characterized by a unique scheduleNumber, a type (e.g. flight, truck) and a
deliveryRoute. Please create an Entity Relation Diagram that captures this information
about Ebebewa K Ltd system. Be certain to indicate identifiers and cardinality
constraints.
Solution
We need to identify the entities, their attributes, and the relationships between them. Here’s a
breakdown:
1. Shipped Item
- Item Number (Primary Key)
- Weight
- Dimensions
- Insurance Amount
- Destination
- Final Delivery Date
2. Retail Center
- Unique ID (Primary Key)
- Type
- Address
3. Transportation Event
- Schedule Number (Primary Key)
- Type (e.g., flight, truck)
- Delivery Route
▎Relationships:
1. Received At:
- A Shipped Item is received at a Retail Center.
- Relationship: Many-to-One (Many Shipped Items can be received at one Retail Center).
2. Involves:
- A Shipped Item can involve multiple Transportation Events during its journey.
- Relationship: Many-to-Many (Many Shipped Items can be transported via many
Transportation Events).
Please convert the ER diagram into a SQL database schema. Be certain to indicate
primary keys and referential integrity constraints.
Solution
Explanation:
• Lot table: Stores information about production lots, including their unique identifier,
creation date, cost of materials, and the raw material from which they were created.
• RawMaterials table: Stores information about raw materials used in production,
including their unique identifier, type, and unit cost.
• ProductionUnits table: Stores information about individual production units,
including their serial number, exact weight, quality test result, product type,
description, and the lot they belong to.
• Includes table: Represents the relationship between lots and production units,
indicating the number of units included in each lot. It has a composite primary key
consisting of LotNumber and serial# to ensure that each unit can only be included in
a lot once.
• The CreatedFrom column in the Lot table references the material_ID column in the
RawMaterials table, ensuring that each lot is associated with a valid raw material.
• The LotNumber column in the ProductionUnits table references the LotNumber
column in the Lot table, ensuring that each production unit belongs to a valid lot.
• The LotNumber and serial# columns in the Includes table reference the
corresponding columns in the Lot and ProductionUnits tables, respectively,
ensuring that each inclusion relationship is valid.
Solution
The designer was likely solving the problem of modeling a many-to-many relationship
between students, courses, and schools. This is a common scenario in educational databases
where a student can enroll in multiple courses at a school, and a course can be taken by
multiple students.
Solution
A potential problem with this solution is that it introduces redundancy in the SCF table. For
example, if a student and a course are associated with the same school, the School attribute
will be repeated in both the SF and SCF tables. This can lead to data inconsistencies and
increased storage requirements.
(c) Describe and comment on the particular features of SQL that makes this solutions
possible.
Solution
• Composite Primary Key: The SCF table uses a composite primary key consisting of
Studld and Courseld to uniquely identify each student-course combination.
• Foreign Keys: The FOREIGN KEY constraints in the SCF table ensure that the Studld
and Courseld values refer to existing records in the SF and CF tables, respectively.
This helps maintain data integrity and prevents invalid references.
• UNIQUE Constraints: The UNIQUE constraints on the (Studld, School) and
(Courseld, School) combinations in the SF and CF tables, respectively, ensure that
each student can only be associated with one school and each course can only be
offered at one school. This prevents duplicate entries and maintains data consistency.
To address the redundancy issue, a possible solution would be to remove the School
attribute from the SCF table and rely on the foreign keys to establish the relationship
between students, courses, and schools. This would eliminate redundancy and improve data
efficiency.
16. With relevant example explain the following terms as used in database Systems.
Solution
Books
BookID (Primary key)
Tittle
Author
PublicationYear
Borrowers
BorrowerID (Primary key)
Name
Address
PhoneNumber
Loans
LoanID (Primary key)
DueDate
(b) Domain
Solution
A domain is a set of permissible values for an attribute. It defines the data type and any
constraints that apply to the values stored in that attribute.
Example:
Solution
Example:
A relation instance for the Books table might look like this:
Solution
Solution
17. Explain the difference between a weak and a strong entity set.
Solution
A strong entity set, also known as an independent entity, is an entity that can be uniquely
identified by its own primary key without needing additional entities while A weak entity set,
also known as a dependent entity, is an entity that cannot be uniquely identified by its own
attributes alone. It depends on a strong entity set for its identification.
18. Describe what you understand by the term ‘Relational Model’ and identify the main
components of relational Model
Solution
The relational model is a structured approach to managing data within a database. It organizes
data into tables (relations), where each table consists of rows (tuples) and columns
(attributes). This model provides a logical and efficient way to store, retrieve, and manipulate
data.
Main Components of the Relational Model
1. Relation (Table):
o A two-dimensional structure with rows and columns.
o Each row represents a record or tuple.
19. Explain the benefits of using ER data modelling techniques to assist in the design of
a relational database.
Solution
1. Clear Visual Representation
• Intuitive Understanding: ER diagrams provide a visual representation of data,
making it easier for both technical and non-technical stakeholders to understand the
database structure.
• Enhanced Communication: The visual nature of ER diagrams facilitates effective
communication between database designers, developers, and business analysts.
2. Efficient Database Design
• Identification of Entities and Relationships: ER diagrams help identify the key
entities (tables) and their relationships (foreign keys) within the database.
• Normalization: ER diagrams aid in normalizing the database, reducing redundancy
and improving data integrity.
• Optimized Data Structure: By visualizing data relationships, designers can create a
well-structured database that is efficient and scalable.
3. Improved Data Integrity
• Enforcing Constraints: ER diagrams help define and enforce data constraints, such
as primary keys, foreign keys, and data types.
• Minimizing Data Inconsistencies: By identifying and addressing potential data
anomalies, ER models contribute to data accuracy and consistency.
4. Facilitated Database Development
• Clear Blueprint: ER diagrams serve as a blueprint for database development, guiding
the creation of tables, relationships, and indexes.
• Streamlined Development Process: A well-defined ER model can accelerate the
development process by providing a clear roadmap for developers.
5. Enhanced Database Maintenance
• Documentation: ER diagrams provide valuable documentation for future reference,
making it easier to understand and modify the database.
• Simplified Changes: Changes to the database schema can be more easily
implemented and assessed when based on an ER model.
20. A well-known supermarket chain sub contracts deliveries from its warehouses to its retail
outlets. In Kenya there are 33 retail outlets and 8 warehouses. Addresses of warehouses and
retail outlets should be stored. The transport company which holds the contract for deliveries
to the retail outlets has a number of vehicles which can carry various weights of goods. It is
important to store data about the volume of goods which each vehicle can carry. Each journey
undertaken by a vehicle involves collecting from one or more outlets. Data about the date,
mileage and driver etc. should be stored for each journey. Each load has a different serial
number and data on the weight, volume, of the load should be stored.
The transport company and the supermarket chain want a database to help in the planning of
deliveries.
Draw an entity relationship diagram to represent the conceptual schema of the database.
Solution
1. Warehouse
• Address
2. Retail Outlet
• Address
3. Vehicle
• Capacity_Weight
• Capacity_Volume
4. Journey
• Date
• Mileage
• Driver_Name
5. Load
• Weight
• Volume
• Serial_Number
▎Relationships
1. Warehouse to Journey
• A journey can involve multiple retail outlets, and a retail outlet can be involved in
multiple journeys (Many to Many). This requires a junction table (JourneyRetailOutlet).
3. Vehicle to Journey
• A vehicle can undertake multiple journeys, but each journey is undertaken by one vehicle
(1 to Many).
4. Journey to Load
• A journey can carry multiple loads, but each load is associated with one journey (1 to
Many).
1. Person
o Attributes: pid (PK), name
2. Skier (Type of Person)
o Attributes: pid (PK), aptitude
3. Snowboarder (Type of Skier)
o Attributes: pid (PK)
4. PairOfSkis
o Attributes: sid (PK), model
5. Snowboard
o Attributes: sid (PK), model
Relationships
1. OwnsPairOfSkis
o Between: Skier and PairOfSkis
o Attributes: purchase_price
22. Computer Sciences Department frequent fliers have been complaining to Kisumu
Intentional Airport officials about the poor organization at the airport. As a result, the
officials decided that all information related to the airport should be organized using a
DBMS, and you have been hired to design the database. Your first task is to organize the
information about all the airplanes stationed and maintained at the airport. The
relevant information is as follows:
(a) Draw an ER diagram for the airport database. Be sure to indicate the
various attributes of each entity and relationship set; also specify the key and
participation constraints for each relationship set. Specify any necessary
overlap and covering constraints as well (in English)
Solution
1. Airplane
o Attributes: registration_number (PK), model_number (FK)
2. Model
o Attributes: model_number (PK), capacity, weight
3. Technician
o Attributes: social_security_number (PK), name, PIN, address, phone_number,
salary
4. TrafficController
o Attributes: social_security_number (PK), recent_exam_date
5. Employee
o Attributes: social_security_number (PK), union_membership_number
6. Test
o Attributes: test_number (PK), name, max_score
7. TestingEvent
o Attributes: date, hours_spent, score, registration_number (FK),
social_security_number (FK), test_number (FK)
Relationships
1. Expertise
o Relationship: Technician (N) --- (N) Model
2. TestedBy
o Relationship: Airplane (N) --- (N) TestingEvent --- (N) Technician
3. UndergoesTest
o Relationship: Airplane (N) --- (N) Test
4. ConductsTest
o Relationship: Technician (N) --- (N) Test
5. WorksAs
o Relationship: Employee (1) --- (1) Technician or TrafficController
• Employee: This entity covers both Technician and TrafficController. Each employee
is either a technician, a traffic controller, or both.
(b). The KCAA passes a regulation that tests on a plane must be conducted by
a technician who is an expert on that model. How would you express this
constraint in the ER diagram? If you cannot express it, explain briefly.
Solution
The regulation that tests on a plane must be conducted by a technician who is an expert on
that model can be represented by ensuring the relationship between Technician, Model, and
TestingEvent considers expertise:
23. What are the two types of null value that are most common? (Give an example of
their use.)
Solution
Unknown Value: When the value is not known at the time of data entry. For example, a new
employee's contact number is not available yet, so the phone number field is left null.
Not Applicable Value: When the field does not apply to a particular record. For example, a
field for "Spouse Name" would be null for unmarried employees.
24. Explain the following terms briefly with appropriate example: attribute,
relationship, one-to-many relationship and many-to-many relationship.
Solution
25. Explain the difference between physical and logical data independence.
Solution
26. Why would you choose a database system instead of simply storing data in operating
system files? When would it make sense not to use a database system?
Solution
Advantages of DBMS:
• Simple and Static Data: For small, simple, and rarely changing datasets, using a
DBMS might be overkill.
• Performance Constraints: For highly performance-sensitive applications, the
overhead of a DBMS might be undesirable.
• Cost: Implementing and maintaining a DBMS can be costly; for small-scale
applications, flat files might be sufficient.
27. What are 'Integrity Constraints'? What role do they play in a DBMS?
Solution
Integrity Constraints: Rules and restrictions applied to database tables to ensure the
accuracy and consistency of data. Examples include primary keys, foreign keys, unique
constraints, and check constraints.
Role in DBMS:
• Maintain Data Accuracy: Ensure that only valid data is entered into the database.
• Enforce Business Rules: Ensure that business logic is adhered to within the database.
28. With examples discuss what you understand by cardinality in database system.
Solution
Cardinality in a database system refers to the uniqueness of data values that can be present in
a column (attribute) of a table, and it describes the relationship between entities in terms of
how many instances of one entity can be associated with instances of another entity. There
are different types of cardinality that help define the nature of these relationships.
Types of Cardinality
1. One-to-One (1:1)
o Description: One entity instance is associated with one and only one instance
of another entity.
o Example: Each person has a unique passport. Here, a "Person" entity is
associated with one "Passport" entity.
2. One-to-Many (1:N)
One Customer can have multiple Orders, but each Order is linked to one Customer.
3. Many-to-One (N:1)
4. Many-to-Many (M:N)
• Description: Multiple instances of one entity are associated with multiple instances of
another entity.
• Example: Students can enroll in multiple courses, and each course can have multiple
students. Here, a "Student" entity is associated with multiple "Course" entities, and
vice versa.
Students and Courses are linked through the Enrollment table which records which students are
enrolled in which courses.
Key Type PK
Null/Unique NN, U NN NN
Default Value System Date
Check 1 to 999999
Data Type Number VARCHAR2 VARCHAR2 Date
Length 10 30 50
(a). Create the EMPLOYEE table based on the table instance chart shown above.
Choose the appropriate data types and be sure to add integrity constraints.
Solution
(b). What is meant by second normal form (2NF)? Examine the following table to check
if it is in 2NF. If yes, explain your answer. If not, convert the table into 2NF.
Solution
A table is said to be in 2NF if it is in 1NF and every non-key attribute is fully functionally
dependent on the entire primary key.
Key Points:
• 1NF: A table is in 1NF if it has no repeating groups and all attributes are atomic.
• Functional Dependency: An attribute B is functionally dependent on an attribute A if
for every value of A, there is only one possible value of B.
Table:
Observations:
• Primary Key: The primary key seems to be a combination of staffNo and branchNo
as it uniquely identifies each row.
• Functional Dependencies:
o branchAddress is functionally dependent on branchNo.
o name, position, and hoursPerWeek are functionally dependent on staffNo.
Conclusion:
The given table is not in 2NF. The attribute branchAddress is functionally dependent only
on branchNo, which is part of the primary key. This violates the 2NF requirement of full
functional dependency on the entire primary key.
Converting to 2NF
To convert the table into 2NF, we can decompose it into two tables:
Table 1: Staff
Table 2: Branch
Solution
Data Type:
• Description: Defines the kind of data that can be stored in the field (e.g., Text,
Number, Date/Time).
• Example: A "BirthDate" field might use the Date/Time data type to store dates of
birth.
Field Size:
• Description: Specifies the maximum size of the data that can be stored in the field.
• Example: A "Name" field might have a Field Size of 50 characters.
Default Value:
• Description: Sets a default value that will be entered automatically if no other value
is specified.
@crispusjoash on all platforms
Page 39 of 51
Validation Rule:
• Description: Defines a rule that data entered into the field must comply with.
• Example: A "Quantity" field might have a validation rule >=0 to ensure that only
non-negative numbers are entered.
30. A university wants to use a database to store information about its departments,
divisions, and employees. Each department at the university has a unique name. Each
department contains several divisions. Divisions in different departments can have the
same name, but the division names within each department are unique. There can be
many employees in each division, but each employee is employed at only one division.
For each employee, their name and their unique personNumber should be stored. There
are two kinds of employees at the university: faculty members and PhD students. For
each PhD student, one faculty member is appointed to be their examiner. Each PhD
student also has one main supervisor, but they can have zero or more co-supervisors.
One faculty member at each department is appointed to be the head of that department.
Similarly, one faculty member at each division is appointed to be the head of that
division.
Solution
1. Department
o Attributes: Department_Name (PK)
2. Division
o Attributes: Division_ID (PK), Division_Name, Department_Name (FK)
3. Employee
o Attributes: PersonNumber (PK), Name, Division_ID (FK)
4. FacultyMember (subclass of Employee)
o Attributes: FacultyID (PK)
5. PhDStudent (subclass of Employee)
o Attributes: PhDStudentID (PK), Examiner (FK), MainSupervisor (FK)
Relationships:
1. HasDivisions
o Relationship: Department (1) --- (N) Division
2. EmployedAt
o Relationship: Division (1) --- (N) Employee
3. Supervises
o Relationship: FacultyMember (1) --- (N) PhDStudent (MainSupervisor),
FacultyMember (1) --- (N) PhDStudent (CoSupervisor)
4. HeadsDepartment
o Relationship: FacultyMember (1) --- (1) Department
5. HeadsDivision
o Relationship: FacultyMember (1) --- (1) Division
(b) Translate this E-R diagram into a set of relations, clearly marking all references and
keys.
Solution
1. Department:
o Attributes: Department_Name (Primary Key)
2. Division:
o Attributes: Division_ID (Primary Key), Division_Name, Department_Name
(Foreign Key references Department)
3. Employee:
o Attributes: PersonNumber (Primary Key), Name, Division_ID (Foreign Key
references Division)
4. FacultyMember:
o Attributes: FacultyID (Primary Key, Foreign Key references Employee),
PersonNumber (Foreign Key references Employee)
5. PhDStudent:
o Attributes: PhDStudentID (Primary Key, Foreign Key references Employee),
PersonNumber (Foreign Key references Employee), Examiner (Foreign Key
references FacultyMember), MainSupervisor (Foreign Key references
FacultyMember)
6. Supervises:
o Attributes: FacultyID (Foreign Key references FacultyMember),
PhDStudentID (Foreign Key references PhDStudent)
7. HeadsDepartment:
o Attributes: FacultyID (Foreign Key references FacultyMember),
Department_Name (Foreign Key references Department)
8. HeadsDivision:
o Attributes: FacultyID (Foreign Key references FacultyMember),
Division_ID (Foreign Key references Division)
Relations Schema
1. Department
o Department_Name (PK)
2. Division
o Division_ID (PK), Division_Name, Department_Name (FK)
3. Employee
o PersonNumber (PK), Name, Division_ID (FK)
4. FacultyMember
o FacultyID (PK, FK), PersonNumber (FK)
5. PhDStudent
o PhDStudentID (PK, FK), PersonNumber (FK), Examiner (FK),
MainSupervisor (FK)
6. Supervises
o FacultyID (FK), PhDStudentID (FK)
7. HeadsDepartment
o FacultyID (FK), Department_Name (FK)
8. HeadsDivision
o FacultyID (FK), Division_ID (FK)
31. The following database contains information about actors, plays, and roles
performed.
1. Actor
2. Play
3. Role
Tables:
Actor: This table contains actors, their names, and the year they were born. Each actor
has a unique `actor_id`, which serves as the primary key.
Play: This table contains plays, their titles, authors, and the year they were written.
Each play has a unique `play_id`, which serves as the primary key.
Role: This table contains the roles performed by actors in different plays. It includes
`actor_id` (Foreign Key), `character_name`, and `play_id` (Foreign Key).
Role records which actors have performed which roles (characters) in which plays.
Attributes actor_id and play_id are foreign keys to Actor and Play respectively. All
three attributes make up the key since it is possible for a single actor to play more than
one character in the same play.
(a). Write the SQL statements that define the relational schema (tables) for this
database. Assume that actor_id, play_id, year_born, and year_written are all integers,
and that name, title, author, and character_name are strings. Be sure to define
appropriate keys and foreign key constraints.
Solution
(b). Write a SQL query that returns the number of actors who have performed in three
or more different plays written by the author "Faith Peter"
Solution
Explanation:
• The Actor table contains columns actor_id (primary key), name, and year_born.
• The Play table contains columns play_id (primary key), title, author, and
year_written.
• The Role table contains columns actor_id (foreign key referencing Actor),
character_name, and play_id (foreign key referencing Play). The primary key for
the Role table is a composite key consisting of actor_id, character_name, and
play_id.
SQL Query:
32. A publishing company produces academic books on various subjects. Books are
written by authors who specialise in one or more particular subjects. The company
employs a number of editors who do not have particular specialisations but who take
sole responsibility for editing one or more publications. A publication covers a single
subject area but may be written by one or more authors -- the contribution of each
author is recorded as a percentage for the purposes of calculating royalties.
Solution
1. Book
o Attributes: Book_ID (PK), Title, Subject
2. Author
o Attributes: Author_ID (PK), Name, Specialization
3. Editor
o Attributes: Editor_ID (PK), Name
4. Publication
o Attributes: Publication_ID (PK), Subject
Relationships
1. Writes
o Relationship: Author (N) --- (N) Book
o Attributes: Contribution_Percentage
2. Edits
o Relationship: Editor (1) --- (N) Publication
(b). What are the three key components of relational database design?
Solution
33. Describe the ANSI/SPARC three level architecture for database management
systems software and explain the advantages it provides.
Solution
• Data Abstraction and Independence: Separates the user and logical views from the
physical storage, enabling changes at one level without affecting others.
@crispusjoash on all platforms
Page 46 of 51
• Improved Security: Different user views at the external level can limit access to
specific parts of the data.
• Simplified Database Design: Provides a structured framework that simplifies the
design and management of the database.
• Easier Maintenance and Updates: Changes to the physical storage or logical
schema can be made without affecting user applications.
34. How are database structures at each of the three levels specified in most database
management systems?
Solution
• Structures are defined using the conceptual schema, which outlines the entire database
structure.
• SQL CREATE TABLE statements, data types, and constraints define entities and their
relationships.
• Example:
• Structures are defined using the internal schema, which includes storage details,
indexing, and file organization.
• Most DBMS provide options to define these aspects through SQL or DBMS-specific
commands.
• Example:
35. SQL by default does not remove duplicate rows. Discuss the main reason for this
approach and illustrate your answer with an SQL query.
Solution
Dependencies:
a2 → a4
c3 → c4
(a). In what normal form are the above relational schemes, given the associated
dependencies? Transform these relations to third normal form, showing the steps
involved.
Solution
• Dependencies: a2 → a4
• Candidate Key: {a1, a2, a3}
Normal Form:
Normal Form:
• Dependencies: c3 → c4
• Candidate Key: {c1, c2, c3}
Normal Form:
• a2 (Primary Key), a4
• c3 (Primary Key), c4
(b). Discuss briefly the purpose of normalisation, detailing also its disadvantages.
Solution
Purpose of Normalization:
Disadvantages of Normalization:
1. Complex Queries: Normalization can lead to complex joins across multiple tables,
which may degrade query performance in read-heavy systems.
2. Increased Time for Insert, Update, Delete: Normalization requires multiple tables
to be updated, which can slow down insert, update, and delete operations.
3. Difficult Data Retrieval: The more normalized the data, the more tables need to be
joined, making data retrieval complex and potentially slower.
4. Design Overhead: Creating a fully normalized database requires careful planning and
design, which can be time-consuming and requires expertise.