0% found this document useful (0 votes)
6 views

DBMS Revision

Uploaded by

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

DBMS Revision

Uploaded by

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

DBMS

Table 1 and Table 2 shows Customers and County relation in a database. Use it to answer the
following questions.

Customers table

Customerid Countyid CustName Date T


1 14 Dan 23/05/1997
2 13 Wendy 20/07/1998
3 40 June 20/08/1998
4 45 Mary 30/09/1999

County Table

Countyid CountyName
12 Meru
14 Embu
40 Busia
48 Kwale

Write a structured SQL statement that was used to;

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)

Differentiate between commit and rollback commands as used in SQL.

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

1. Relational Database Model: In a relational database, a many-to-many relationship can


be implemented using a junction table (also known as a bridge table or associative
entity). This table contains foreign keys that reference the primary keys of the two related
tables.
2. NoSQL Database Model: In NoSQL databases like MongoDB, many-to-many
relationships can be represented using embedded documents or arrays within a document,
which allows for more flexible schema design and scalability.

5(a)

Outline two conditions necessary for relations to be union compatible.

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)

Outline four benefits of storing data using cloud computing technology.

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.

(i) Rectangle: Represents an entity in an Entity Relationship Diagram (ERD).

(ii) Oval: Represents an attribute in an Entity Relationship Diagram (ERD).

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)

Outline two types of aliases in SQL.

1. Column Alias: Provides a temporary name for a column in a result set.


o Example: SELECT column_name AS alias_name FROM table_name;
2. Table Alias: Provides a temporary name for a table, often used to simplify queries.
o Example: SELECT a.column_name FROM table_name AS a;

6(b)

A supermarket that has several branches uses a distributed database system. Explain three
benefits it could accrue from this system.

1. Increased Availability: Distributed databases ensure data is available at multiple


locations, reducing the risk of a single point of failure.
2. Improved Performance: By distributing the load across multiple servers, distributed
databases can handle more transactions and queries efficiently.
3. Localized Data Access: Branches can access data locally, reducing latency and
improving response times for operations.

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.

 Example: SELECT e1.salary FROM employees e1 WHERE e1.salary > (SELECT


AVG(e2.salary) FROM employees e2 WHERE e1.department_id = e2.department_id);

(ii) Distinguish between degree and cardinality in a database table.

 Degree: Refers to the number of attributes (columns) in a table.


 Cardinality: Refers to the number of tuples (rows) in a table.

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.

Given table in 1NF:


OrderID ItemID Description Quantity Unit Price
OD001 IT45 Cartilage 5 2000
OD001 IT42 Printing papers 20 1000
OD002 IT45 Cartilage 4 2000
OD003 IT52 Marker pen 25 250

Identify functional dependencies and separate tables:

 Orders: OrderID -> Quantity


 Items: ItemID -> Description, Unit Price

Orders Table:

OrderID ItemID Quantity


OD001 IT45 5
OD001 IT42 20
OD002 IT45 4
OD003 IT52 25

Items Table:

ItemID Description Unit Price


IT45 Cartilage 2000
IT42 Printing papers 1000
IT52 Marker pen 250

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.

7(b)Jacqueline added a record in a database table. Explain three properties of such a


transaction.
1. Atomicity: Ensures that all operations within the transaction are completed; if not, the
transaction is aborted and the database remains unchanged.
2. Consistency: Ensures that the database remains in a consistent state before and after the
transaction.
3. Isolation: Ensures that transactions are isolated from each other and do not affect each
other's execution.
4. Durability: Ensures that once a transaction is committed, the changes are permanent,
even in the case of a system failure.

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

003 Assistant Lecturer

008 Lecturer

005 Professor

Table 7: Lecturer

LecturerNo LecturerName GradeID Salary Age YearEmployed

L345675 Eunice 003 30000 45 1982

L347890 Agnes 003 45000 60 1985

L345679 Alex 002 56000 55 1989

L456782 Ted 008 25000 22 1996


LecturerNo LecturerName GradeID Salary Age YearEmployed

L789073 Felix 012 15000 35 1994

L897032 Gladys 015 50000 30 1998

(i) State an appropriate data type for the field named GradeName.

 Varchar or String: GradeName VARCHAR(255)

(ii) Write SQL statements to perform each of the following:

(I) Display the LecturerNo, LecturerName and Salary of all the lecturers with GradeName
"Assistant Lecturer".

SELECT LecturerNo, LecturerName, Salary


FROM Lecturer
JOIN Grade ON Lecturer.GradeID = Grade.GradeID
WHERE GradeName = 'Assistant Lecturer';

(II) Display the LecturerNo, GradeID and Salary for all Lecturers above age 50 and
YearEmployed is between 1980 and 1992.

SELECT LecturerNo, GradeID, Salary


FROM Lecturer
WHERE Age > 50 AND YearEmployed 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:

(i) Reviewing of existing organizational documentation:

1. Understand Current Systems: Reviewing existing documentation helps Jane


understand the current database systems, workflows, and processes in place, providing a
foundation for the new system.
2. Identify Requirements and Gaps: It allows Jane to identify the requirements that the
new system needs to fulfill and any gaps or inefficiencies in the current system that need
to be addressed.

(ii) Understanding the current operating environment:

1. Compatibility and Integration: Understanding the current operating environment


ensures that the new database management system will be compatible with existing
hardware, software, and network infrastructure.
2. Resource Allocation: It helps in planning resource allocation, such as hardware,
software, and personnel, to ensure smooth implementation and operation of the new
system.

Sure, let's provide the answers for the questions on the scanned document.

(c) Table 2 SQL Questions

(i) SQL Statement to Generate the Table


CREATE TABLE Employees (
EmpID CHAR(5),
Name VARCHAR(50),
Position VARCHAR(50),
Salary INT
);
(ii) SQL Statements for the Given Tasks

1. Add the first record into the table:

INSERT INTO Employees (EmpID, Name, Position, Salary)


VALUES ('EM100', 'Gordon', 'Senior Manager', 150000);

2. Delete the last record from the table:

DELETE FROM Employees


WHERE EmpID = 'EM106';

3. Change the name of Thomas to Samuel:

UPDATE Employees
SET Name = 'Samuel'
WHERE Name = 'Thomas';

4. Display the least salary:

SELECT MIN(Salary) AS LeastSalary


FROM Employees;

(a) Self-Join in SQL

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

1. A∪BA \cup BA∪B (Union)

Name Mark
---- ----
Luke 80
Serah 70
Newton 68
Matthew 86

2. A−BA - BA−B (Difference)

Name Mark
---- ----
Luke 80
Serah 70
3. A×BA \times BA×B (Cartesian Product)

Name Mark Name Mark


---- ---- ---- ----
Luke 80 Matthew 86
Luke 80 Newton 68
Serah 70 Matthew 86
Serah 70 Newton 68
Newton 68 Matthew 86
Newton 68 Newton 68

(c) Classification of SQL Commands

 ALTER: Data Definition Language (DDL)


 DROP: Data Definition Language (DDL)
 MERGE: Data Manipulation Language (DML)
 SELECT: Data Manipulation Language (DML)

(d) Types of Indexes Sarah Could Use

1. Single-Column Index: An index on a single column of a table. Improves the speed of


data retrieval operations for that column.
2. Composite Index: An index on multiple columns. Useful for queries that filter on
multiple columns and can improve performance by reducing the need to search multiple
single-column indexes.

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.

You might also like