DBMS Revision
DBMS Revision
Table 1 and Table 2 shows Customers and County relation in a database. Use it to answer the
following questions.
Customers table
County Table
Countyid CountyName
12 Meru
14 Embu
40 Busia
48 Kwale
I. Create the Customers relation with the relevant fields as shown in table 1 having the field
Customerid as the primary a key.
CREATE TABLE Customers (
Customerid INT PRIMARY KEY,
Countyid INT,
CustName VARCHAR(50),
DateT DATE
);
II. Set the field Countyid as the foreign key in the customer relation
ALTER TABLE Customers
ADD CONSTRAINT fk_County
FOREIGN KEY (Countyid)
REFERENCES County(Countyid);
Write a structured Query language statements that would be used to display the fields
Customerid, CustName, and CountyName from the two relations
SELECT
Customers.Customerid,
Customers.CustName,
County.CountyName
FROM
Customers
JOIN
County
ON
Customers.Countyid = County.Countyid;
4(c)
Commit: The COMMIT command is used to save all changes made in the current
transaction to the database. Once a COMMIT is issued, the changes become permanent
and cannot be undone.
Rollback: The ROLLBACK command is used to undo all changes made in the current
transaction. This means that the database is restored to its previous state before the
transaction began.
4(d)
Joan intends to develop a database system that supports a many-to-many relationship.
Describe two database models she could use.
5(a)
1. Same Number of Attributes: Both relations must have the same number of attributes
(columns).
2. Same Domain for Each Attribute: The attributes in both relations must have the same
domain, meaning they must be of the same data type and in the same order.
5(b)
1. Scalability: Cloud computing allows for easy scaling of resources to meet increasing
data storage needs without significant upfront investment.
2. Cost Efficiency: Pay-as-you-go pricing models help reduce costs as you only pay for the
storage and resources you use.
3. Accessibility: Data stored in the cloud can be accessed from anywhere with an internet
connection, facilitating remote work and collaboration.
4. Security: Cloud providers often offer robust security measures, including data
encryption, backup, and disaster recovery solutions.
5(c)
Describe each of the following notations in an Entity Relationship Diagram.
5(d)
(i) Differentiate between entity integrity and referential integrity as used in database
systems.
Entity Integrity: Ensures that each table has a primary key and that the primary key is
unique and not null. This ensures that each record can be uniquely identified.
Referential Integrity: Ensures that a foreign key value always points to an existing,
valid record in another table. This maintains consistency among related tables.
(ii) Janet prefers to use views rather than base tables in SQL. Explain three reasons for this
preference.
1. Simplified Querying: Views can simplify complex queries by encapsulating them into a
single virtual table.
2. Security: Views can restrict access to specific rows and columns, providing a layer of
security by controlling what data users can see.
3. Data Abstraction: Views provide a level of abstraction, allowing users to interact with a
virtual table that may present data in a more meaningful way than the underlying base
tables.
6(a)
6(b)
A supermarket that has several branches uses a distributed database system. Explain three
benefits it could accrue from this system.
6(c)
(i) Explain the term correlated subquery as used in SQL. A correlated subquery is a subquery
that refers to a column from the outer query. This means that the subquery is executed once for
each row processed by the outer query.
6(d)
Normalize the table to 2NF. To normalize the given table to the Second Normal Form (2NF),
we need to ensure that it is in the First Normal Form (1NF) and that all non-key attributes are
fully functionally dependent on the primary key.
Orders Table:
Items Table:
7(a)Explain the term closure property in relational algebra. The closure property in
relational algebra states that the result of any operation on one or more relations is always a
relation. This means that relational operations can be applied repeatedly, and the results will
always be valid relations.
Sure, here are the answers to the questions provided in the image:
6(c)Tables 6 and 7 are extracts from a database. Use them to answer the
questions that follow:
Table 6: Grade
GradeID GradeName
002 Tutor
008 Lecturer
005 Professor
Table 7: Lecturer
(i) State an appropriate data type for the field named GradeName.
(I) Display the LecturerNo, LecturerName and Salary of all the lecturers with GradeName
"Assistant Lecturer".
(II) Display the LecturerNo, GradeID and Salary for all Lecturers above age 50 and
YearEmployed is between 1980 and 1992.
(III) Display all details of the lecturers whose age is not captured in the table Lecturer.
SELECT *
FROM Lecturer
WHERE Age IS NULL;
6(d)
Jane intends to commence the requirements gathering phase for the development of a
database management system in her organization. Outline two reasons why she should
consider each of the following during the phase:
Sure, let's provide the answers for the questions on the scanned document.
UPDATE Employees
SET Name = 'Samuel'
WHERE Name = 'Thomas';
A self-join is a regular join but the table is joined with itself. It is used to compare rows within
the same table. For example, if you have a table of employees and their managers, you can use a
self-join to find employees who report to the same manager.
(b) Relational Algebra Operations
Given tables:
Table A
Name Mark
---- ----
Luke 80
Serah 70
Newton 68
Table B
Name Mark
---- ----
Matthew 86
Newton 68
Name Mark
---- ----
Luke 80
Serah 70
Newton 68
Matthew 86
Name Mark
---- ----
Luke 80
Serah 70
3. A×BA \times BA×B (Cartesian Product)
3. Unique Index: Ensures that the values in the indexed column(s) are unique across the
table. Automatically created with a unique constraint or primary key.