Docsity

Database Design and Query Processing: A Practical Guide with Exercises - Prof. Edwin, Lecture notes of Database Management Systems (DBMS)

Toggle sidebar
bg1
1
1 Query Processing
1.1 Introduction
In this lesson, we shall utilize some simple databases to illustrate the concepts of query
processing.
Class Exercise 1:
Test your proficiency in designing, implementing, and using a database by recalling the
skills gained during the previous course.
The following are the steps involved in designing and implementing a database, given
some requirement.
i. Requirements Analysis
ii. Conceptual Model
iii. Normalization
iv. ERD
v. Database Schema
Objective: Create a database based on a brief set of requirements provided.
“In Meru University of Science and Technology, there are various schools (eg. SBE, SAFS
etc.). Each school has one or more departments (eg. CS, IT, Nursing etc). Each department
has its programs (eg. BCT, BIT, BCS, BEd. Etc). When a student is admitted into the
University, he/she is enrolled into a program.”
Use the above information to;
a) Requirements analysis - Summarize the above case into (entities, relationships,
cardinalities, and attributes)
b) Translate the above requirements into a conceptual model
c) Normalize the conceptual model in b (above)
d) Translate the conceptual model into an ERD
e) Translate the ERD to a physical model (Create a database)
While making reference to the database schema generated after completing the above
exercise, test your basic SQL proficiency by attempting to write SQL query commands to;
i) List the names and email of all students
ii) List the names and email of all students whose names begin with ‘MA’
iii) List the names and email of all students registered for ‘BBIT’
pf3
pf4

Partial preview of the text

Download Database Design and Query Processing: A Practical Guide with Exercises - Prof. Edwin and more Lecture notes Database Management Systems (DBMS) in PDF only on Docsity!

1 Query Processing

1.1 Introduction In this lesson, we shall utilize some simple databases to illustrate the concepts of query processing. Class Exercise 1: Test your proficiency in designing, implementing, and using a database by recalling the skills gained during the previous course. The following are the steps involved in designing and implementing a database, given some requirement. i. Requirements Analysis ii. Conceptual Model iii. Normalization iv. ERD v. Database Schema Objective: Create a database based on a brief set of requirements provided. “In Meru University of Science and Technology, there are various schools (eg. SBE, SAFS etc.). Each school has one or more departments (eg. CS, IT, Nursing etc). Each department has its programs (eg. BCT, BIT, BCS, BEd. Etc). When a student is admitted into the University, he/she is enrolled into a program.” Use the above information to; a) Requirements analysis - Summarize the above case into (entities, relationships, cardinalities, and attributes) b) Translate the above requirements into a conceptual model c) Normalize the conceptual model in b (above) d) Translate the conceptual model into an ERD e) Translate the ERD to a physical model (Create a database) While making reference to the database schema generated after completing the above exercise, test your basic SQL proficiency by attempting to write SQL query commands to; i) List the names and email of all students ii) List the names and email of all students whose names begin with ‘MA’ iii) List the names and email of all students registered for ‘BBIT’

iv) List the names and email of all students from IT department v) List the names and email of all students taking programs from IT and Nursing departments. vi) List the names, email of all students who have not enrolled to any program. vii) List the names of programs with no students enrolled. Class Exercise 2: Library database. The purpose of the database is to facilitate staff members to issue books to the library patrons. The three major entities (table) are:  Staff – staff members of the library  patrons – registered users of the library.  Books – Library inventory or items How are these entities related? In this problem we need to know which books are issued to which patrons and by whom (staff). Thus, the relationship “issues/issued” becomes an obvious and an important relationship in this simple problem. Normalizing the design, the relationship is represented using a new entity, “issues”. Finally, the resulting Entity- Relationship Diagram is as follows; While making reference to the ERD above, test your basic SQL proficiency by attempting to write commands to; i. List the names and email of all patrons who have ever been issued with a book authored by ‘Stephen Mutua’;

A number of search algorithms are possible for selecting the records from a file. The selection of records from a file is known as file scan, as the algorithm scans the records of a file to search for and retrieve records that satisfy the selection condition. Index Scan If the search algorithm uses an index to perform the search, then it is referred as Index Scan.

  • Linear Search: This is also known as Brute Force method. In this method, every record in the file is retrieved and tested as to whether its attribute values satisfy the selection condition.
  • Binary Search: If a selection condition involves an equality comparison on a key attribute on which the file is ordered, a binary search can be used. Binary search is more efficient than linear search.
  • Primary Index Single Record Retrieval: If a selection condition involves an equality comparison on a primary key attribute with a primary index, we can use the primary index to retrieve that record.
  • Secondary Index: This search method can be used to retrieve a single record if the indexing field has unique values (key field) or to retrieve multiple records if the indexing field is not a key. This can also be used for comparisons involving <, >, <= or >= Primary Index Multiple Records Retrieval: A search condition uses comparison condition <, >, etc. on a key field with primary index is known as Primary index multiple records retrieval.
  • Clustering Index: If the selection condition involves an equality comparison on a non- key attribute with a clustering index, we can use that index to retrieve all the records satisfying the condition. Conjunctive Condition If the selection condition of the SELECT operation is a conjunctive condition (a condition that is made up of several simple conditions with the AND operator), then the DBMS can use the following additional methods to perform the selection. Conjunctive selection: If an attribute in any single simple condition in the conjunctive condition has an access path that permits use of binary search or an index search, use that condition to retrieve the records and then check if that record satisfies the remaining condition. Conjunctive selection using composite index: If two or more attributes are involved in equality conditions in the conjunctive condition and a composite index exists on the combined fields we can use the index.