0% found this document useful (0 votes)
25 views51 pages

BCS 221-1

The document provides a comprehensive guide on designing and implementing a database system for a health club, detailing steps such as identifying entities, defining relationships, and normalizing data. It also explains the three levels of database structures in DBMS, the importance of database systems for organizations, and the responsibilities of a DBMS, including data storage, integrity, security, and concurrency control. Additionally, it discusses techniques for maintaining data integrity during concurrent access and the differences between logical and physical data independence.

Uploaded by

deryquehenryques
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views51 pages

BCS 221-1

The document provides a comprehensive guide on designing and implementing a database system for a health club, detailing steps such as identifying entities, defining relationships, and normalizing data. It also explains the three levels of database structures in DBMS, the importance of database systems for organizations, and the responsibilities of a DBMS, including data storage, integrity, security, and concurrency control. Additionally, it discusses techniques for maintaining data integrity during concurrent access and the differences between logical and physical data independence.

Uploaded by

deryquehenryques
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Page 1 of 51

BCS 221 | BIT 213:INTRODUCTION TO DATABASE SYSTEMS:


A QUICK REVISION GUIDE:
BASICS TO ADVANCED
1. You are asked to design a database system for a health club. The database would
contain data about customers, their training, contact numbers, etc. Show the main step
you would perform for designing and implementing the database. (Don’t show the
actual schemas!)
Solution

1. Identify Entities and Attributes:

• Entities: Customers, Training Sessions, Instructors, Membership Plans, Facilities


• Attributes:
o Customers: Customer ID, Name, Contact Information, Membership Type,
Membership Start Date, Membership End Date
o Training Sessions: Session ID, Date, Time, Instructor, Facility, Attendees
(many-to-many relationship with Customers)
o Instructors: Instructor ID, Name, Qualifications, Contact Information
o Membership Plans: Plan ID, Name, Duration, Cost
o Facilities: Facility ID, Name, Location, Equipment

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.

3. Create an Entity-Relationship (ER) Diagram:

• Visualize the entities and their relationships using an ER diagram. This helps in
understanding the structure of the database.

4. Normalize the Data:

• 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.

5. Choose a Database Management System (DBMS):

• 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.

6. Create Database Tables:

@crispusjoash on all platforms


Page 2 of 51

• Translate the ER diagram into database tables, defining the columns (attributes) for
each table and their data types.

7. Populate the Database with Data:

• Insert relevant data into the tables. This may involve importing data from existing
systems or manually entering it.

8. Implement Security Measures:

• Protect sensitive data by implementing security measures such as user authentication,


access controls, and data encryption.

9. Test and Optimize:

• Thoroughly test the database to ensure it functions as expected and identify any
performance bottlenecks. Optimize the database as needed to improve query
performance.

10. Implement Maintenance Procedures:

• Establish regular maintenance routines, including backups, updates, and performance


monitoring, to keep the database running smoothly.

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.

@crispusjoash on all platforms


Page 3 of 51

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.

Relationship between the Levels:

• 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

Reasons for Embracing Database Systems

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:

1. Data Management and Organization:

• Centralized Storage: Database systems provide a centralized location to store and


manage large volumes of data.
• Data Integrity: They ensure data consistency, accuracy, and integrity by enforcing
data validation rules and preventing redundancy.
• Data Security: Database systems offer robust security features to protect sensitive
data from unauthorized access, modification, or loss.
• Data Accessibility: They provide easy access to data from multiple locations and
applications, facilitating collaboration and information sharing.

2. Improved Decision Making:

• Data Analysis: Database systems enable organizations to analyze data to identify


trends, patterns, and insights.
• Reporting: They support the creation of customized reports and dashboards to
visualize data and make informed decisions.
• Business Intelligence: Database systems can be integrated with business intelligence
tools to provide valuable insights for strategic planning and decision-making.

3. Enhanced Efficiency and Productivity:

@crispusjoash on all platforms


Page 4 of 51

• 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:

• Data-Driven Decision Making: Organizations that effectively leverage database


systems can gain a competitive advantage by making data-driven decisions.
• Customer Insights: They can better understand customer preferences and behavior,
leading to improved customer satisfaction and loyalty.
• Innovation: Database systems can support innovation by providing the foundation for
new products, services, and business models.

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.

4. List at least four responsibilities of a database management system. For each


responsibility, explain the problems that would arise if the responsibility were not
discharged, if these responsibilities were not met by a given DBM, what problems
occur?
Solution
1. Data Storage and Retrieval:
• Responsibility: Storing data in a structured and organized manner, and efficiently
retrieving it when needed.
• Problems if not met:
o Data Loss: If the DBMS cannot reliably store and retrieve data, it can lead to
significant data loss, which can have severe consequences for an organization.
o Inefficient Operations: Slow retrieval times can hinder productivity and
decision-making.
o Inaccurate Results: Errors in data storage or retrieval can lead to incorrect
information and poor decision-making.

@crispusjoash on all platforms


Page 5 of 51

2. Data Integrity and Consistency:


• Responsibility: Ensuring that data is accurate, consistent, and free from errors.
• Problems if not met:
o Incorrect Decisions: Inaccurate data can lead to poor decision-making,
resulting in financial losses, reputational damage, and operational
inefficiencies.
o Data Corruption: Inconsistent data can corrupt the database, making it
difficult to use and maintain.
o Legal and Regulatory Issues: Violations of data integrity can lead to legal
and regulatory problems, especially in industries with strict compliance
requirements.
3. Data Security and Access Control:
• Responsibility: Protecting data from unauthorized access, modification, or deletion,
and controlling who can access and modify data.
• Problems if not met:
o Data Breaches: A lack of security can lead to data breaches, exposing
sensitive information to unauthorized parties.
o Financial Loss: Data breaches can result in significant financial losses due to
fines, legal costs, and damage to reputation.
o Loss of Trust: Customers and stakeholders may lose trust in an organization
if their data is compromised.
4. Concurrency Control:
• Responsibility: Managing concurrent access to the database by multiple users or
applications to ensure data consistency and avoid conflicts.
• Problems if not met:
o Data Inconsistencies: Without proper concurrency control, multiple users can
modify the same data simultaneously, leading to inconsistencies and errors.
o Lost Updates: Updates made by one user may be lost if another user modifies
the same data before the first update is committed.
o Deadlocks: If multiple users are waiting for each other to release locks on
resources, a deadlock can occur, preventing further progress.
5. In your own words, explain how data integrity is maintained within the database
when concurrent users access the database.
Solution
@crispusjoash on all platforms
Page 6 of 51

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:

Description: A transaction is a sequence of operations performed as a single logical


unit of work. Transactions ensure that either all operations are completed
successfully, or none are.

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:

o Description: Concurrency control mechanisms manage the simultaneous


execution of transactions to prevent conflicts and ensure data consistency.

@crispusjoash on all platforms


Page 7 of 51

o Example: Techniques like locking (where a transaction locks the data it is


working on) and timestamp ordering (where transactions are ordered based on
their start time) help manage concurrent access.

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.

8. Atomicity, Consistency, Isolation, Durability (ACID) Properties:

o Description: These properties ensure reliable processing of database


transactions.
1. Atomicity: Ensures that all operations within a transaction are
completed; if not, the transaction is aborted.
2. Consistency: Ensures that a transaction brings the database from one
valid state to another.
3. Isolation: Ensures that transactions are executed in isolation from each
other.
4. Durability: Ensures that once a transaction is committed, it remains
so, even in the event of a system failure.
o Example: If a power failure occurs after a transaction is committed, the
changes made by the transaction will still be present when the system is back
up, thanks to durability.

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.

@crispusjoash on all platforms


Page 8 of 51

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.

8. Consider the SQL query whose answer is shown below.


sid name login age gpa
1234 Grace grace@mmust 19 1.9
5678 John john@mmust 29 2.0

Student with age < 18 on instance S


(a) Write a query that will return the above table without the condition in place
assuming there are only two records in the table.
Solution

Understanding the Original Query:

Without the specific SQL query, we can infer the following based on the result set:

@crispusjoash on all platforms


Page 9 of 51

• There's a table named Student.


• The table has columns: sid, name, login, age, and gpa.
• The condition age < 18 is filtering the results.

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

@crispusjoash on all platforms


Page 10 of 51

6745 Omondi PA5.90 Alpha DA32 KSM FN1 Packer 3/8/06


4519 Mtua PA8.19 Omega DA09 KSM FN1 Packer 30/3/07
GR2 Grinder 23/2/09
GR3 Grinder 21/2/10

(a). What is the meaning of the term ‘functional dependency’?


Solution
A functional dependency is a relationship between attributes in a relation (table) where the
values of one attribute (or set of attributes) determine the values of another attribute (or set of
attributes). In other words, if you know the values of one attribute, you can uniquely
determine the values of another.
Example: In a student database, if StudentID determines StudentName, then StudentName is
functionally dependent on StudentID, represented as StudentID → StudentName1
(b). Convert the table into first normal form.
Solution
To convert the table into First Normal Form (1NF), we need to ensure that each column
contains only atomic (indivisible) values and that each record is unique. Here is the converted
table:

(c). Why is important to develop functional dependencies during normalization?


Solution
Developing functional dependencies during normalization is crucial because:

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.

@crispusjoash on all platforms


Page 11 of 51

(d). Give TWO reasons why the WORKRECORD table is not in third normal form.
Solution

1. Transitive Dependency: The table contains transitive dependencies where non-key


attributes depend on other non-key attributes. For example, Dept. Loc. depends
on Dept. No, which is not a primary key.
2. Partial Dependency: The table has partial dependencies where non-key attributes
depend on a part of a composite primary key. For instance, Grade Title depends
on Grade No and not on the entire primary key.
3. Non-Key Attribute Dependency: Dept.No and Dept.Loc depend on EmpNo through
the primary key EmpNo, ProjectNo. These attributes are not part of the primary key
but depend on it.

(e). Fully identify at least one occurrence of redundant data.


Solution
Redundant Data Example: The Project Name “Alpha” is repeated multiple times for
different employees and project numbers. This redundancy can lead to inconsistencies if the
project name changes but is not updated in all instances.

(f). Write down the functional dependencies implied by the table.


Solution
Here are some functional dependencies implied by the table:

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

Entity-Relationship (ER) data modeling is a powerful technique used to represent the


structure of a database system. It provides a visual representation of entities (objects or
concepts), attributes (properties of entities), and relationships between entities. ER diagrams
are invaluable in designing relational databases due to the following benefits:

1. Clear Conceptual Understanding:

@crispusjoash on all platforms


Page 12 of 51

• Visual Representation: ER diagrams present a clear and concise visual


representation of the database structure, making it easier to understand the
relationships between entities and attributes.
• Semantic Clarity: They help to define the semantics of the data, ensuring that the
database accurately reflects the real-world concepts and relationships.

2. Improved Data Integrity:

• Entity-Relationship Constraints: ER diagrams can explicitly represent constraints


such as cardinality (one-to-one, one-to-many, many-to-many) and participation
(mandatory or optional) between entities. These constraints help ensure data
consistency and prevent errors.
• Data Validation: By defining the relationships and constraints upfront, ER diagrams
can help identify and prevent potential data anomalies and inconsistencies.

3. Enhanced Database Design:

• Normalization: ER diagrams can be used to identify potential normalization issues


and guide the design of normalized database structures, reducing redundancy and
improving performance.
• Efficiency: By understanding the relationships between entities and attributes,
database designers can create more efficient and optimized database structures.

4. Facilitated Communication:

• Common Language: ER diagrams provide a common language for database


designers, developers, and end-users to communicate about the database structure and
requirements.
• Collaboration: They can be used to collaborate with stakeholders to ensure that the
database meets their needs and expectations.

5. Reduced Development Time:

• Faster Design: By providing a clear and concise visual representation, ER diagrams


can help speed up the database design process.
• Fewer Errors: A well-designed ER diagram can help reduce the likelihood of errors
and inconsistencies in the database implementation.

6. Scalability:

• Adaptability: ER diagrams can be easily modified to accommodate changes in the


database requirements, making it easier to scale the database as the organization
grows.

In conclusion, ER data modeling is a valuable tool for designing relational databases. It


provides a clear and concise visual representation of the data structure, helps ensure data
integrity, improves database design, facilitates communication, reduces development time,
and promotes scalability. By using ER diagrams, database designers can create more
efficient, reliable, and maintainable database systems.

@crispusjoash on all platforms


Page 13 of 51

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

▎Entities and Attributes:

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).

▎ER Diagram Representation:

Here’s how you can visualize the ER diagram:

@crispusjoash on all platforms


Page 14 of 51

!!!This is only a sketch and not the real representation!!!

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:

(a) A description of the data design phase.

(b) The inputs of the phase.

(c) The outputs of the phase.

(d) A key issue addressed in the phase.

@crispusjoash on all platforms


Page 15 of 51

(e) A challenge that you anticipate can occur in the phase.

Solution

Data Design Work Plan

Phase 1: Requirements Gathering and Analysis

• 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.

Phase 2: Conceptual Data Modeling

• Description: This phase involves creating a high-level conceptual model of the


database, representing the main entities, attributes, and relationships.
• Inputs: Requirements document, data dictionary, and initial ER diagrams.
• Outputs: Refined ER diagrams, data flow diagrams, and entity-relationship attribute
diagrams.
• Key Issue: Ensuring that the conceptual model accurately captures the business
requirements and is well-structured.
• Anticipated Challenge: Balancing the need for a simple and understandable model
with the complexity of the business domain.

Phase 3: Logical Data Modeling

@crispusjoash on all platforms


Page 16 of 51

• 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.

Phase 4: Physical Data Modeling

• Description: This phase involves designing the physical implementation of the


database, including storage structures, indexes, and constraints.
• Inputs: Logical data model, database platform selection, performance requirements.
• Outputs: Physical database design, storage allocation plans, and index creation
strategies.
• Key Issue: Optimizing the physical design for performance, scalability, and
maintainability.
• Anticipated Challenge: Balancing performance requirements with storage costs and
complexity.

Phase 5: Data Validation and Testing

• 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.

@crispusjoash on all platforms


Page 17 of 51

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:

▎Entities and Attributes:

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:

@crispusjoash on all platforms


Page 18 of 51

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).

▎ER Diagram Representation:

Here’s how you can visualize the ER diagram:

!!!This is only a sketch and not the real representation!!!

14. Product tracking is important in many manufacturing environments. (e.g., the


pharmaceuticals industry, children’s toys, etc.). The following ER diagram captures
important information in the tracking of production. Specifically, the ER diagram
captures relationships between production lots (or batches), individual production
units, and raw materials.

@crispusjoash on all platforms


Page 19 of 51

Please convert the ER diagram into a SQL database schema. Be certain to indicate
primary keys and referential integrity constraints.

Solution

@crispusjoash on all platforms


Page 20 of 51

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.

Referential integrity constraints:

• 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.

@crispusjoash on all platforms


Page 21 of 51

• 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.

15. Consider the following SQL definition

(a) What problem was the designer solving.

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.

(b) What possible problem remains in the solution.

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

@crispusjoash on all platforms


Page 22 of 51

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

The SQL features that make this solution possible are:

• 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.

(a). A relational database schema

Solution

A relational database schema is a blueprint or logical structure that defines the


organization of data within a relational database. It specifies the tables (relations),
their columns (attributes), and the relationships between them.
Example:
Consider a simple database for a library:

Books
BookID (Primary key)
Tittle
Author
PublicationYear

Borrowers
BorrowerID (Primary key)
Name

@crispusjoash on all platforms


Page 23 of 51

Address
PhoneNumber

Loans
LoanID (Primary key)

BookID (foreign key referencing Books.BookID)

BorrowerID (foreign key referencing


Borrowers.BorrowerID)
LoanDate

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:

In the Books table above:

• The domain of BookID might be INTEGER (integer numbers).


• The domain of Title might be STRING(100) (character strings up to 100 characters).
• The domain of PublicationYear might be INTEGER with a constraint to be between
1500 and the current year.

(c) A relation instance

Solution

A relation instance is a specific snapshot of data stored in a relation at a particular point in


time. It's a collection of tuples (rows) that conform to the relation's schema.

Example:

A relation instance for the Books table might look like this:

BookID Tittle Author PublicationYear


1 "The Lord of the J.R.R. Tolkien 1954
Rings"

@crispusjoash on all platforms


Page 24 of 51

2 "Pride and Jane Austen 1813


Prejudice"
3 "To Kill a Harper Lee 1960
Mockingbird"

(d) The relation cardinality

Solution

The relation cardinality is the number of tuples (rows) in a relation instance.


Example:
In the Books relation instance above, the cardinality is 3, as there are 3 tuples.

(e) The relation degree

Solution

The relation degree is the number of attributes (columns) in a relation.


Example:
In the Books relation, the degree is 4, as there are 4 attributes: BookID, Title, Author, and
PublicationYear.

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.

@crispusjoash on all platforms


Page 25 of 51

o Each column represents an attribute or field.


2. Tuple (Row):
o A single record within a relation.
o Contains values for each attribute of the relation.
3. Attribute (Column):
o A named column within a relation.
o Defines the type of data that can be stored in that column.
4. Domain:
o A set of permissible values for an attribute.
o Defines the data type and any constraints on the values.
5. Primary Key:
o A unique identifier for each tuple in a relation.
o Ensures that each row is distinct.
6. Foreign Key:
o A reference to the primary key of another relation.
o Used to establish relationships between tables.
7. Integrity Constraints:
o Rules that ensure data accuracy and consistency.
o Examples:
▪ Entity Integrity: Every relation must have a primary key.
▪ Referential Integrity: Foreign keys must reference valid primary
keys.
Example:
Consider a simple database for a library:
1 "The Lord of the J.R.R. Tolkien 1954
Rings"
2 "Pride and Jane Austen 1813
Prejudice"
3 "To Kill a Harper Lee 1960
Mockingbird"
In this example:
• Relation: Books
• Tuples: Each row represents a tuple.
• Attributes: BookID, Title, Author, PublicationYear
• Primary Key: BookID
The relational model's simplicity, flexibility, and powerful query language (SQL) have made
it the foundation for many modern database systems.

@crispusjoash on all platforms


Page 26 of 51

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.

@crispusjoash on all platforms


Page 27 of 51

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

!!!This is only a sketch and not the real representation!!!

▎Entities and Attributes

1. Warehouse

• Warehouse_ID (Primary Key)

• Address

2. Retail Outlet

• Outlet_ID (Primary Key)

• Address

3. Vehicle

• Vehicle_ID (Primary Key)

@crispusjoash on all platforms


Page 28 of 51

• Capacity_Weight

• Capacity_Volume

4. Journey

• Journey_ID (Primary Key)

• Date

• Mileage

• Driver_Name

5. Load

• Load_ID (Primary Key)

• Weight

• Volume

• Serial_Number

▎Relationships

1. Warehouse to Journey

• A warehouse can be associated with multiple journeys (1 to Many).

2. Retail Outlet 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).

21. Design an E/R diagram describing the following domain:


i A Person has attributes pid (key) and name.
ii A Skier is a type of Person with attribute aptitude.
iii A Snowboarder is a type of Skier.
iv A PairOfSkis has attribute sid (key) and model.

@crispusjoash on all platforms


Page 29 of 51

v A Snowboard has attribute sid (key) and model.


vi A Skier owns zero or more PairOfSkis. The ownership relation has a
purchase price. A PairOfSkis is owned by at most one Skier.
vii A Snowboarder owns zero or more Snowboards. The ownership relation
has a purchase price. A Snowboard is owned by at most one Snowboarder.
viii A Person can rent a PairOfSkis or a Snowboard. A person cannot rent
more than one PairOfSkis or one Snowboard at the same time. A person
cannot rent a PairOfSkis and a Snowboard at the same time either. A
piece of equipment can be rented by at most one person at a time. The
rental comes with a start date and an end date.
Solution

Entities and Attributes

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

@crispusjoash on all platforms


Page 30 of 51

o Relationship: Skier (1) --- (N) PairOfSkis


2. OwnsSnowboard
o Between: Snowboarder and Snowboard
o Attributes: purchase_price
o Relationship: Snowboarder (1) --- (N) Snowboard
3. RentsEquipment
o Between: Person and PairOfSkis, Person and Snowboard
o Attributes: start_date, end_date
o Relationship: Person (1) --- (1) PairOfSkis, Person (1) --- (1)
Snowboard

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:

• Every airplane has a registration number, and each airplane is of a


specific model.
• The airport accommodates a number of airplane models, and each model
is identified by a model number (e.g., MN-10) and has a capacity and a
weight.
• A number of technicians work at the airport. You need to store the name,
PIN, address, phone number, and salary of each technician.
• Each technician is an expert on one or more plane model(s), and his or her
expertise may overlap with that of other technicians. This information
about technicians must also be recorded.
• Traffic controllers must have an annual medical examination. For each
traffic controller, you must store the date of the most recent exam.

• All airport employees (including technicians) belong to a union. You must


store the union membership number of each employee. You can assume
that each employee is uniquely identified by a social security number.
• The airport has a number of tests that are used periodically to ensure that
airplanes are still airworthy. Each test has a Kenya Civil Aviation
Authority (KCAA) test number, a name, and a maximum possible score.
• The KCAA requires the airport to keep track of each time a given
airplane is tested by a given technician using a given test. For each testing
event, the information needed is the date, the number of hours the
technician spent doing the test, and the score the airplane received on the
test.

@crispusjoash on all platforms


Page 31 of 51

(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

Entities and Attributes

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

@crispusjoash on all platforms


Page 32 of 51

Participation and Key Constraints

• Airplane-Model: An airplane must be of one model.


• Expertise: A technician can be an expert on multiple models, and each model can
have multiple experts.
• TestingEvent: Each testing event is uniquely identified by the combination of date,
reg_number, ssn, and test_number.

Overlap and Covering Constraints

• Employee: This entity covers both Technician and TrafficController. Each employee
is either a technician, a traffic controller, or both.

@crispusjoash on all platforms


Page 33 of 51

(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:

Additional Relationship Constraint

• TestingEvent: Ensure the relationship Expertise between Technician and Model is


a prerequisite for TestingEvent. This means a TestingEvent can only occur if the
Technician is already an expert on the Model of the Airplane.

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

• Attribute: A property or characteristic of an entity. Example: In a "Student"


entity, attributes could be StudentID, Name, and DateOfBirth.
• Relationship: An association between two or more entities. Example: A
"Professor" teaches "Course" is a relationship between "Professor" and "Course".
• One-to-Many Relationship: A single entity is associated with multiple entities in
another entity set. Example: A "Customer" can place multiple "Orders".
• Many-to-Many Relationship: Multiple entities in one set are associated with
multiple entities in another set. Example: Students can enroll in multiple courses,
and each course can have multiple students.

25. Explain the difference between physical and logical data independence.

Solution

@crispusjoash on all platforms


Page 34 of 51

• Physical Data Independence: The capacity to change the physical schema


without having to change the logical schema. Example: Modifying the storage
format or the indexing strategy.
• Logical Data Independence: The capacity to change the logical schema without
having to change the external schema or applications. Example: Adding a new
field to a table without affecting existing applications.

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:

• Data Integrity and Security: DBMS provides mechanisms to ensure data


consistency and access control.
• Data Redundancy and Inconsistency: DBMS reduces redundancy and avoids
inconsistencies by normalizing data.
• Data Independence: DBMS abstracts the data from applications, enabling flexibility
and scalability.
• Efficient Data Access: DBMS offers optimized query processing and indexing for
fast data retrieval.
• Backup and Recovery: DBMS provides robust backup and recovery mechanisms to
protect data.
• Concurrent Access: DBMS supports multi-user environments, allowing concurrent
access to data.

When Not to Use a 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.

@crispusjoash on all platforms


Page 35 of 51

• Prevent Data Anomalies: Reduce the likelihood of data inconsistencies and


anomalies by enforcing rules on relationships between entities.

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.

Each Person is linked to one Passport and vice versa.

2. One-to-Many (1:N)

• Description: One entity instance is associated with multiple instances of another


entity.
• Example: A single customer can place multiple orders. Here, a "Customer" entity
is associated with multiple "Order" entities.

One Customer can have multiple Orders, but each Order is linked to one Customer.

3. Many-to-One (N:1)

• Description: Multiple instances of an entity are associated with one instance of


another entity. This is essentially the inverse of the One-to-Many relationship.
• Example: Multiple employees work in one department. Here, an "Employee" entity is
associated with one "Department" entity.

@crispusjoash on all platforms


Page 36 of 51

Many Employees belong to one Department.

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.

29. Consider the following table instance chart

Table name: EMPLOYEE

Column Name EMP ID EMP NAME ADDRESS JOIN DATE

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.

@crispusjoash on all platforms


Page 37 of 51

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.

Analysis of the Given Table

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.

@crispusjoash on all platforms


Page 38 of 51

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

(c.) Discuss any four field properties in MS Access

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

• Example: An "OrderDate" field could have a default value of Date() to


automatically insert the current date.

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.

(a). Draw an E-R diagram that correctly models this domain.

Solution

Entities and Attributes:

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

@crispusjoash on all platforms


Page 40 of 51

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

@crispusjoash on all platforms


Page 41 of 51

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.

@crispusjoash on all platforms


Page 42 of 51

1. Actor

- Attributes: actor_id (Primary Key), name, year_born

2. Play

- Attributes: play_id (Primary Key), title, author, year_written

3. Role

- Attributes: actor_id (Foreign Key), character_name, play_id (Foreign Key)

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

@crispusjoash on all platforms


Page 43 of 51

(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:

Creating the Tables:

• 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.

@crispusjoash on all platforms


Page 44 of 51

• 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:

• The query joins the Role and Play tables on play_id.


• It filters the plays written by "Faith Peter" using the WHERE clause.
• It groups the results by actor_id and uses the HAVING clause to count only those
actors who have performed in three or more different plays by the specified author.
• The final result counts the number of such actors using COUNT(DISTINCT actor_id).

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.

(a). Draw an ER diagram to represent the above specification

Solution

Entities and Attributes

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

@crispusjoash on all platforms


Page 45 of 51

33. Describe the ANSI/SPARC three level architecture for database management
systems software and explain the advantages it provides.

Solution

The ANSI/SPARC three-level architecture is a framework that outlines the layers of a


database management system (DBMS) to separate user applications from the physical
database. It includes the following levels:

1. External Level (User View)


o This level describes how individual users view the data. It includes multiple
user views or external schemas tailored to different user requirements,
ensuring each user interacts with the database in a way that meets their needs
without seeing the underlying complexity.
2. Conceptual Level (Logical View)
o This level describes the structure of the entire database for a community of
users. It defines the logical structure of the data as seen by the database
administrator (DBA) and includes entities, relationships, and constraints. The
conceptual schema hides the physical storage details and focuses on data
models like relational, object-oriented, etc.
3. Internal Level (Physical View)
o This level describes the physical storage of the database on the hardware. It
includes the internal schema, which details how data is stored and accessed,
such as file structures, indexing methods, and record placement. This level
ensures efficient storage and retrieval of data.

Advantages of the ANSI/SPARC Architecture:

• 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

External Level (User View)

• Structures are specified using external schemas or views.


• SQL CREATE VIEW statements define the subset of data accessible to specific users.
• Example:

Conceptual Level (Logical View)

• 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:

Internal Level (Physical View)

• 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:

@crispusjoash on all platforms


Page 47 of 51

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

• SQL is designed to be a set-based language where operations return sets of rows. In


many cases, duplicates are legitimate and meaningful in representing data accurately.
Removing duplicates by default would lead to data loss and misrepresentation of the
actual dataset.
• Specific scenarios where duplicates are required:
o Transactional Data: Multiple transactions with the same amount.
o Survey Responses: Identical responses from different respondents.

Example SQL Query:

• To illustrate the behavior of SQL returning duplicates:

@crispusjoash on all platforms


Page 48 of 51

36. Use the following

A(a1, a2, a3, a4)

B(b1, (b2, b3))

C(c1, c2, c3, c4)

Dependencies:

@crispusjoash on all platforms


Page 49 of 51

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

1. Checking Normal Form

Relation A(a1, a2, a3, a4)

• Dependencies: a2 → a4
• Candidate Key: {a1, a2, a3}

Normal Form:

• 1NF: Yes, all attributes are atomic.


• 2NF: No, because a4 is partially dependent on a2, which is a part of the candidate
key.
• 3NF: No, because it is not in 2NF.

Relation B(b1, b2, b3)

• Dependencies: No dependencies provided.


• Candidate Key: {b1, b2, b3} (assuming no dependencies)

Normal Form:

• 1NF: Yes, all attributes are atomic.


• 2NF: Yes, as there are no partial dependencies (since no dependencies provided).
• 3NF: Yes, as there are no transitive dependencies (since no dependencies provided).

Relation C(c1, c2, c3, c4)

• Dependencies: c3 → c4
• Candidate Key: {c1, c2, c3}

Normal Form:

• 1NF: Yes, all attributes are atomic.


• 2NF: No, because c4 is partially dependent on c3, which is a part of the candidate
key.
• 3NF: No, because it is not in 2NF.

2. Transforming to Third Normal Form (3NF)

@crispusjoash on all platforms


Page 50 of 51

Transforming Relation A(a1, a2, a3, a4)

• Decompose based on the partial dependency a2 → a4:


1. Relation A1(a2, a4) where a2 is the primary key.
2. Relation A2(a1, a2, a3) where (a1, a2, a3) is the primary key.

Relation A1(a2, a4)

• a2 (Primary Key), a4

Relation A2(a1, a2, a3)

• a1, a2, a3 (Composite Primary Key)

Transforming Relation C(c1, c2, c3, c4)

• Decompose based on the partial dependency c3 → c4:


1. Relation C1(c3, c4) where c3 is the primary key.
2. Relation C2(c1, c2, c3) where (c1, c2, c3) is the primary key.

Relation C1(c3, c4)

• c3 (Primary Key), c4

Relation C2(c1, c2, c3)

• c1, c2, c3 (Composite Primary Key)

(b). Discuss briefly the purpose of normalisation, detailing also its disadvantages.

Solution

Purpose of Normalization:

1. Eliminate Redundancy: By dividing tables to eliminate duplicate data, normalization


ensures that each piece of information is stored only once.
2. Enhance Data Integrity: Normalization enforces referential integrity, ensuring that
relationships between tables remain consistent.
3. Simplify Data Management: Normalized tables are easier to maintain and update,
reducing the risk of data anomalies and inconsistencies.
4. Improve Query Performance: By optimizing the structure, normalization helps
improve the efficiency of queries and reduce storage space.

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.

@crispusjoash on all platforms


Page 51 of 51

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.

@crispusjoash on all platforms

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy