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

IM 201 Worksheets

This document provides a learning module on the fundamentals of database systems. It includes exercises, applications, and summaries on various topics related to database systems including defining key terms, discussing database architectures, and writing SQL statements.

Uploaded by

james jerez
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)
12 views

IM 201 Worksheets

This document provides a learning module on the fundamentals of database systems. It includes exercises, applications, and summaries on various topics related to database systems including defining key terms, discussing database architectures, and writing SQL statements.

Uploaded by

james jerez
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/ 49

IM 201

Fundamentals of Database Systems

Learning Module on IM 201


STUDENT
Name:
Student Number:
Program:
Section:
Home Address:
Email Address:
Contact Number:

PROFESSOR
Name:
Academic Department:
Consultation Schedule:
Email Address:
Contact Number:

Learning Module on IM 201


23

M1:L1 Exercise
a. Define the following terms: data, database, DBMS, database system, database catalog, program-data
independence, user view, DBA, end user, canned transaction, deductive database system, persistent object, meta-
data, and transaction-processing application.

b. What four main types of actions involve databases? Briefly discuss each.

c. Discuss the main characteristics of the database approach and how it differs from traditional file systems.

Learning Module on IM 201


24

d. Discuss the capabilities that should be provided by a DBMS.

e. Discuss the differences between database systems and information retrieval systems.

M1:L1 Application
a. Cite some examples of integrity constraints that you think can apply to the database shown in Figure 1.2.

Learning Module on IM 201


25

b. Give examples of systems in which it may make sense to use traditional file
processing instead of a database approach.

Learning Module on IM 201


26

Summary of the Lesson:


1. In this chapter we defined a database as a collection of related data, where data means recorded facts. A typical
database represents some aspect of the real world and is used for specific purposes by one or more groups of
users. A DBMS is a generalized software package for implementing and maintaining a computerized database.
The database and software together form a database system.
2. We identified several characteristics that distinguish the database approach from traditional file-processing
applications, and we discussed the main categories of database users, or the actors on the scene. We noted that in
addition to database users, there are several categories of support personnel, or workers behind the scene, in a
database environment.
3. We presented a list of capabilities that should be provided by the DBMS software to the DBA, database
designers, and end users to help them design, administer, and use a database. Then we gave a brief historical
perspective on the evolution of database applications. We pointed out the recent rapid growth of the amounts and
types of data that must be stored in databases, and we discussed the emergence of new systems for handling “big
data” applications. Finally, we discussed the overhead costs of using a DBMS and discussed some situations in
which it may not be advantageous to use one.

Learning Module on IM 201


27

M1:L1 Enrichment Activity


a. If the name of the ‘CS’ (Computer Science) Department changes to ‘CSSE’ (Computer Science and Software
Engineering) Department and the corresponding prefix for the course number also changes, identify the columns
in the database that would need to be updated.

b. Give a one sentence description of each of the tasks you listed for question number 1.

Learning Module on IM 201


46

M1:L2 EXERCISE.
a. Define the following terms: data model, database schema, database state, internal schema, conceptual schema,
external schema, data independence, DDL, DML, SDL, VDL, query language, host language, data sublanguage,
database utility, catalog, client/server architecture, three-tier architecture, and n-tier architecture.

b. What is the difference between logical data independence and physical data independence? Which one is harder
to achieve? Why?

c. What is the difference between the two tier and three-tier client/server architecture.

Learning Module on IM 201


47

M1:L2 Application
If you were designing a Web-based system to make airline reservations and to sell airline tickets, which DBMS
Architecture would you choose from? Why? Why would the other architectures not be a good choice?

Learning Module on IM 201


48

Summary of the Lesson:


1. In this chapter we introduced the main concepts used in database systems. We defined a data model and we
distinguished three main categories:
■ High-level or conceptual data models (based on entities and relationships)
■ Low-level or physical data models
■ Representational or implementation data models (record-based, object oriented)
2. We distinguished the schema, or description of a database, from the database itself. The schema does not change
very often, whereas the database state changes every time data is inserted, deleted, or modified. Then we described
the three-schema DBMS architecture, which allows three schema levels:
■ An internal schema describes the physical storage structure of the database.
■ A conceptual schema is a high-level description of the whole database.
■ External schemas describe the views of different user groups.
3. A DBMS that cleanly separates the three levels must have mappings among the schemas to transform requests
and query results from one level to the next. Most DBMSs do not separate the three levels completely. We used
the three-schema architecture to define the concepts of logical and physical data independence.
4. Then we discussed the main types of languages and interfaces that DBMSs support.

Learning Module on IM 201


49

M1:L2 Enrichment Activity:


a. In addition to constraints relating the values of columns in one table to columns in another table, there are also
constraints that impose restrictions on values in a column or a combination of columns within a table. One such
constraint forces that a column or a group of columns must be unique across all rows in the table. For example,
in the STUDENT table, the StudentNumber column must be unique (to prevent two different students from having
the same StudentNumber). Identify the column or the group of columns in the other tables that must be unique
across all rows in the table.

Learning Module on IM 201


75

M1:L3 EXERCISE.
a. Write the correct SQL statement to create a new database called ccc;

b. SQL statement creates a full back up of the existing database "ccc" to file path “D:\backups\” with file name
“cccdb”:

c. SQL statement to use database ccc.

d. Write the correct SQL statement to create a new table called student. With the following columns and
datatypes:
studentID int,
LastName varchar(255)
FirstName varchar(255)
Address varchar(255)

e. SQL statement to add "course" column with datatype and size varchar(150) to the "student" table:

f. SQL statement to drop "course" column in "student" table:

Learning Module on IM 201


76

g. SQL statement to drop the existing database "ccc".

h. SQL statement to show all databases.

M1:L3 Application
Solve the following problem based on the given data below of Company ABC; note that your answer should be
reflected to the below info:
Database name: abcDB
Table name: worker

1. SQL statement to create database for company ABC.

2. SQL statement to show all databases;

3. SQL statement to use your newly created database for company ABC.

Learning Module on IM 201


77

4. SQL statement to create the database table of Company ABC based on the given table with the following
datatype and size; note that column name should not be changed based on the table above.

Worker id – int(10),
First name- char(25),
Last name – char(25),
Salary – int(15),
Joining date - datetime,
Department – char(25)
Note: datetime do not have size

Learning Module on IM 201


78

Summary of the Lesson:


1. In this chapter we introduced the capabilities of SQL.
2. Discussed the installation process of XAMPP localhost server to run SQL commands.
3. Discussed the operators and datatypes that can be used and the Database SQL statements.

Learning Module on IM 201


79

M1:L3 Enrichment Activity


Solve the following problem based on the given data below of Company DEF; note that your answer should be
reflected to the below info:
Database name: defDB
Table name: title

1. SQL statement to create database for company DEF.

2. SQL statement to show all databases;

3. SQL statement to use your newly created database for company DEF.

4. SQL statement to create the database table of Company DEF based on the given table with the following
datatype and size; note that column name should not be changed based on the table above.

Learning Module on IM 201


80

Worker reference id – int(10),


Worker title- char(25),
Affected from - datetime
Note: datetime do not have size

Learning Module on IM 201


81

M1 Assessment:
I. Identify the below responsibilities whether it is for database designer or database administrator. Write
DBD for database administrator otherwise DBA for database designer on the space provided before each
number.
__________________1. Conducting data backups
__________________2. Assessing database performance
__________________3. Modifying database structure if needed
__________________4. Restoring lost data
__________________5. communicate with all prospective database users
__________________6. Debugging programs or installing patches
__________________7. authorizing access to the database
__________________8. acquiring software
__________________9. purchasing hardware resources as needed
__________________10. responsible for identifying the data to be stored in the database
__________________11. choosing appropriate structures to represent and store this data
__________________12. implement the database design
__________________13. tune database performance
__________________14. install the database server software
__________________15. plan how the logical storage structure of the database will affect system performance

II. Create the schema from the below two views derived from the database. Write your answer on the space
provided.

Learning Module on IM 201


82

III. Write the SQL statement for the below problems on the lines provided.
1. Write the correct SQL statement to create a new database called teashop;
__________________________________________________________________________________________
__________________________________________________________________
2. SQL statement creates a full back up of the existing database " teashop " to file path “D:\backup\” with file
name “teashop_db”:
__________________________________________________________________________________________
__________________________________________________________________
3. SQL statement to use database teashop.

Learning Module on IM 201


83

__________________________________________________________________________________________
__________________________________________________________________
4. Write the correct SQL statement to create a new table called cust. With the following columns and datatypes:
custID int(10),
custLastName varchar(255)
custFirstName varchar(255)
custAddress varchar(255)
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
____________________________________________________________________________________
5. SQL statement to add "order_type" column with datatype and size varchar(250) to the "student" table:
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________
6. SQL statement to drop "course" column in "student" table:
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________
7. SQL statement to drop the existing database "teashop".
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________
8. SQL statement to show all databases.
__________________________________________________________________________________________
__________________________________________________________________________________________

Learning Module on IM 201


84

I. Course Code IM 201


II. Course Title Fundamentals of Database Systems
III. Module Number 2
IV. Module Title SQL Commands and Relational Model
V. Overview of the Module This module will discuss SQL. SQL is a standard language for storing,
manipulating and retrieving data in databases. It is a standard language for
accessing and manipulating databases. It will also tackle the relational database.
The relational data model was first introduced by Ted Codd of IBM Research in
1970 in a classic paper (Codd, 1970), and it attracted immediate attention due to
its simplicity and mathematical foundation. The model uses the concept of a
mathematical relation—which looks somewhat like a table of values—as its
basic building block, and has its theoretical basis in set theory and first-order
predicate logic. In this chapter we discuss the basic characteristics of the model.
VI. Module Outcomes Once you have mastered the material, you will be able to: identify basic
commands of SQL; execute basic commands of SQL; apply basic commands of
SQL; identify the different database models; understand the concept relational
model; and identify the different relational keys that are being used in databases.

Learning Module on IM 201


114

M2:L1 EXERCISE.
Write false if the statement is true otherwise true. Write your answer on the space provided before each number.
__________________a. The WHERE clause is used to extract only those records that fulfill a specified condition.
__________________b. SQL requires single quotes around text values (most database systems will also allow
double quotes).
__________________c. The AND operator displays a record if all the conditions separated by AND is TRUE.
__________________d. The OR operator displays a record if any of the conditions separated by OR is TRUE.
__________________e. The NOT operator displays a record if the condition(s) is NOT TRUE.
__________________f. The COUNT() function returns the number of rows that matches a specified criteria.
__________________g. The AVG() function returns the average value of a numeric column.
__________________h. The SUM() function returns the total sum of a numeric column.
__________________i. If you are adding values for all the columns of the table, you do not need to specify the
column names in the SQL query.
__________________j. The WHERE clause specifies which record(s) should be deleted. If you omit the WHERE
clause, all records in the table will be deleted.

M2:L1 Application
Create the SQL command for the below problems; use the table below for the instance of the database.
DB Name: Company_ABC
DB Table: Employee
EMP_id EMP_name EMP_sex EMP_add EMP_byear EMP_hdate EMP_basicpay
San Pablo
1 John M City 1990 2009 25000
San Pablo
2 Eve F City 1994 2011 24000
Calamba
3 Matt M City 1992 2005 30000
Calamba
4 Mary F City 1987 2002 35000

Learning Module on IM 201


115

1. SQL command to create database Company_ABC.


__________________________________________________________________________________________
________________________________________________________________________________
2. SQL command to create table Employee.
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
____________________________________________________________
3. SQL command to insert employee 1.
__________________________________________________________________________________________
________________________________________________________________________________
4. SQL command to insert employee 2.
__________________________________________________________________________________________
________________________________________________________________________________
5. SQL command to insert employee 3.
__________________________________________________________________________________________
________________________________________________________________________________
6. SQL command to insert employee 4.
__________________________________________________________________________________________
________________________________________________________________________________
7. SQL command to get the sum of basic pay of all employees.
__________________________________________________________________________________________
________________________________________________________________________________
8. SQL command to count all male employees residing at San Pablo City.
__________________________________________________________________________________________
________________________________________________________________________________

Learning Module on IM 201


116

Summary of the Lesson:


1. SQL lets you access and manipulate databases
2. What Can SQL do?
o SQL can execute queries against a database
o SQL can retrieve data from a database
o SQL can insert records in a database
o SQL can update records in a database
o SQL can delete records from a database
o SQL can create new databases
o SQL can create new tables in a database
o SQL can create stored procedures in a database
o SQL can create views in a database
o SQL can set permissions on tables, procedures, and views

3. SQL is a Standard however, to be compliant with the ANSI standard, they all support at least the major
commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar manner. Most of the SQL
database programs also have their own proprietary extensions in addition to the SQL standard.

Learning Module on IM 201


117

M2:L1 Enrichment Activity:


Use the above table and info in application to solve the below problems.
a. SQL command to count all female employees residing at Calamba City.
__________________________________________________________________________________________
________________________________________________________________________________
b. SQL command to get the age of employee 2.
__________________________________________________________________________________________
________________________________________________________________________________
c. SQL command to count employees that were hired from 2000 to 2010 and currently residing at San Pablo City.
__________________________________________________________________________________________
________________________________________________________________________________
d. SQL command to show all databases.
__________________________________________________________________________________________
________________________________________________________________________________
e. SQL command to show all tables.
__________________________________________________________________________________________
________________________________________________________________________________

Learning Module on IM 201


135

M2:L2 EXERCISE.
Identify the relational keys that is being asked on each problem, use the below tables to create your answer; write
your answer on the lines provided.

a. Superkeys in table students:


__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________
b. Superkeys in table subject:
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________
______________________________________________________________________________
c. Candidate keys in all tables:
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
______________________________

Application

Learning Module on IM 201


136

Create a relationship between the three (3) tables given below by providing correct foreign keys to the blank
columns; use the below facts to create your answer. Encircle all primary keys on each table.
• Below is the teaching load of the Professors:
ProfID SubjectCode
101 CS101
102 IS101
103 IT101

• All BSIT students are currently enrolled in IT101.


• All BSCS students are currently enrolled in CS101.
• All BSIS students are currently enrolled in IS101.

table: student
studentID studentName Address Course
2015123 Jenny Brgy. 1 BSIT
2015124 Albert Brgy. 2 BSIT
2015125 Simon Brgy. 1 BSCS
2015126 Jean Brgy. 1 BSCS
2015127 Veronica Brgy. 1 BSIT
2015128 Sean Brgy. 2 BSCS
2015129 Dave Brgy. 3 BSIS
2015130 Mae Brgy. 4 BSIS

table: subject
SubjectCode SubjectName
IT101 Intro to IT
CS101 Intro to CS
IS101 Intro to IS

table: prof
ProfID ProfName Department
101 John CS
102 Smith IS
103 Robert IT

Learning Module on IM 201


137

Summary of the Lesson:


1. In this chapter, we introduced the SQL database language.
2. A database most often contains one or more tables. Each table is identified by a name. Most of the actions
you need to perform on a database are done with SQL statements.
3. A key in SQL is an attribute or set of attributes which helps you to identify a row(tuple) in a relation(table).
DBMS keys allow you to establish a relationship between and identify the relation between tables.
Seven Types of DBMS keys are Super, Primary, Candidate, Alternate, Foreign, Compound, Composite, and
Surrogate Key.
• A super key is a group of single or multiple keys which identifies rows in a table.
• A column or group of columns in a table which helps us to uniquely identifies every row in that table is
called a primary key.
• All the keys which are not primary key are called an alternate key.
• A super key with no repeated attribute is called candidate key.
• A compound key is a key which has many fields which allow you to uniquely recognize a specific record.
• A key which has multiple attributes to uniquely identify rows in a table is called a composite key.
• An artificial key which aims to uniquely identify each record is called a surrogate key.
• Primary Key never accept null values while a foreign key may accept multiple null values.

Learning Module on IM 201


138

M2:L2 Enrichment Activity:


Answer the below problems using the three (3) tables on the previous exercise.
a. Primary keys in student and subject tables:
__________________________________________________________________________________________
__________________________________________________________________
b. Composite key in table enroll.
__________________________________________________________________________________________
__________________________________________________________________
c. Secondary keys in table student and subject.
__________________________________________________________________________________________
__________________________________________________________________
c. Foreign key in table student.
__________________________________________________________________________________________
________________________________________________________________________________

Learning Module on IM 201


139

M2 Assessment:
I. Multiple choice. Write your answer on the space provided before each number.

________1. A column which is added to create a relationship with another table.


a. Foreign Key b. Primary Key c. Super Key d. Candidate Key e. Alternate Key f. Surrogate Key
________2. Helps to maintain data integrity and also allows navigation between two different instances of an
entity.
a. Foreign Key b. Primary Key c. Super Key d. Candidate Key e. Alternate Key f. Surrogate Key
________3. A group of single or multiple keys which identifies rows in a table.
a. Foreign Key b. Primary Key c. Super Key d. Candidate Key e. Alternate Key f. Surrogate Key
________4. A key that may have additional attributes that are not needed for unique identification.
a. Foreign Key b. Primary Key c. Super Key d. Candidate Key e. Alternate Key f. Surrogate Key
________5. An attribute whose values match primary key values in the related table.
a. Foreign Key b. Primary Key c. Super Key d. Candidate Key e. Alternate Key f. Surrogate Key
________6. An artificial key which aims to uniquely identify each record.
a. Foreign Key b. Primary Key c. Super Key d. Candidate Key e. Alternate Key f. Surrogate Key
________7. A minimal super key.
a. Foreign Key b. Primary Key c. Super Key d. Candidate Key e. Alternate Key f. Surrogate Key
________8. With SQL, how do you select all the records from a table named "Persons" where the "LastName" is
alphabetically between (and including) "Hansen" and "Pettersen"?
a. SELECT LastName>'Hansen' AND LastName<'Pettersen' FROM Persons
b. SELECT * FROM Persons WHERE LastName BETWEEN 'Hansen' AND 'Pettersen'
c. SELECT * FROM Persons WHERE LastName>'Hansen' AND LastName<'Pettersen'
________9. Which SQL statement is used to extract data from a database?
d. EXTRACT e. GET f. OPEN g. SELECT
________10. Which SQL statement is used to update data in a database?
h. MODIFY i. UPDATE j. SAVE AS k. SAVE

Learning Module on IM 201


140

________11. Which SQL statement is used to delete data from a database?


l. COLLAPSE m. REMOVE n. DELETE
________12. Which SQL statement is used to insert new data in a database?
o. INSERT NEW s. ADD NEW q. INSERT INTO r. ADD RECORD
________13. With SQL, how do you select a column named "FirstName" from a table named "Persons"?
e. EXTRACT FirstName FROM Persons d. SELECT Persons.FirstName z. SELECT FirstName FROM
Persons
________14. With SQL, how do you select all the columns from a table named "Persons"?
a. SELECT [all] FROM Persons o. SELECT *.Persons y. SELECT Persons e. SELECT * FROM
Persons
________15. With SQL, how do you select all the records from a table named "Persons" where the value of the
column "FirstName" is "Peter"?
r. SELECT [all] FROM Persons WHERE FirstName LIKE 'Peter'
p. SELECT * FROM Persons WHERE FirstName<>'Peter'
h. SELECT * FROM Persons WHERE FirstName='Peter'
s. SELECT [all] FROM Persons WHERE FirstName='Peter'
________16. With SQL, how do you select all the records from a table named "Persons" where the value of the
column "FirstName" starts with an "a"?
p. SELECT * FROM Persons WHERE FirstName='%a%'
o. SELECT * FROM Persons WHERE FirstName LIKE 'a%'
u. SELECT * FROM Persons WHERE FirstName='a'
y. SELECT * FROM Persons WHERE FirstName LIKE '%a'
________17. With SQL, how do you select all the records from a table named "Persons" where the "FirstName"
is "Peter" and the "LastName" is "Jackson"?
c. SELECT * FROM Persons WHERE FirstName='Peter' AND LastName='Jackson'
v. SELECT FirstName='Peter', LastName='Jackson' FROM Persons
f. SELECT * FROM Persons WHERE FirstName<>'Peter' AND LastName<>'Jackson'
________18. Which SQL statement is used to return only different values?

Learning Module on IM 201


141

d. SELECT UNIQUE o. SELECT DIFFERENT g. SELECT DISTINCT


________19. With SQL, how can you insert a new record into the "Persons" table?
r. INSERT ('Jimmy', 'Jackson') INTO Persons
s. INSERT VALUES ('Jimmy', 'Jackson') INTO Persons
t. INSERT INTO Persons VALUES ('Jimmy', 'Jackson')
________20. With SQL, how can you insert "Olsen" as the "LastName" in the "Persons" table?
p. INSERT INTO Persons ('Olsen') INTO LastName
q. INSERT ('Olsen') INTO Persons (LastName)
e. INSERT INTO Persons (LastName) VALUES ('Olsen')
________21. How can you change "Hansen" into "Nilsen" in the "LastName" column in the Persons table?
v. UPDATE Persons SET LastName='Nilsen' WHERE LastName='Hansen'
b. MODIFY Persons SET LastName='Nilsen' WHERE LastName='Hansen'
f. UPDATE Persons SET LastName='Hansen' INTO LastName='Nilsen'
p. MODIFY Persons SET LastName='Hansen' INTO LastName='Nilsen
________22. With SQL, how can you return the number of records in the "Persons" table?
o. SELECT COLUMNS(*) FROM Persons
w. SELECT NO(*) FROM Persons
p. SELECT COUNT(*) FROM Persons
q. SELECT LEN(*) FROM Persons

II. Write the SQL statement for the below problems; write your answer on the lines provided.
Table name: employee

Learning Module on IM 201


142

1. SQL statement to select all employees with an Fname starting with "j":
__________________________________________________________________________________________
__________________________________________________________________
2. SQL statement to select all employees with an Lname ending with "g":
__________________________________________________________________________________________
__________________________________________________________________
3. SQL statement to select all employees with an Address that have "as" in any position:
__________________________________________________________________________________________
__________________________________________________________________
4. SQL statement to select all employees with an Address that have "e" in the second position:
__________________________________________________________________________________________
__________________________________________________________________
d. SQL statement to select all employees with an Fname that starts with "b" and are at least 3 characters in length:
__________________________________________________________________________________________
__________________________________________________________________
e. SQL statement to select all employees with an Fname that starts with "b" and ends with "e":
__________________________________________________________________________________________
__________________________________________________________________
f. SQL statement to select all employees with an Address that does NOT start with "f":
__________________________________________________________________________________________
__________________________________________________________________
8. SQL statement to select all employees with an Fname starting with "e":
__________________________________________________________________________________________
__________________________________________________________________
9. SQL statement to select all employees with an Lname ending with "c":
__________________________________________________________________________________________
__________________________________________________________________
10. SQL statement to select all employees with an Address that have "if" in any position:
__________________________________________________________________________________________
__________________________________________________________________11. SQL statement to select all
employees with an Address that have "t" in the second position:

Learning Module on IM 201


143

__________________________________________________________________________________________
__________________________________________________________________
12. SQL statement to select all employees with an Fname that starts with "c" and are at least 3 characters in length:
__________________________________________________________________________________________
__________________________________________________________________
13. SQL statement to select all employees with an Fname that starts with "w" and ends with "e":
__________________________________________________________________________________________
__________________________________________________________________
14. SQL statement to select all employees with an Address that does NOT start with "k":
__________________________________________________________________________________________
__________________________________________________________________
15. SQL statement to display distinct values of SSN of all male employees.
__________________________________________________________________________________________
__________________________________________________________________
16. SQL statement to display distinct values of SSN of all female employees.
__________________________________________________________________________________________
__________________________________________________________________
17. SQL statement to display distinct values of SSN of all employees.
__________________________________________________________________________________________
__________________________________________________________________
18. SQL statement to display the total salary of all employees.
__________________________________________________________________________________________
__________________________________________________________________
19. SQL statement to count all employees.
__________________________________________________________________________________________
__________________________________________________________________
20. SQL statement to count all female and male employees.
__________________________________________________________________________________________
__________________________________________________________________

Learning Module on IM 201


144

I. Course Code IM 201


II. Course Title Fundamentals of Database Systems
III. Module Number 3
IV. Module Title Database Normalization and SQL Join and ER Model
V. Overview of the Module Database Normalization is a technique of organizing the data in the
database. Normalization is a systematic approach of decomposing tables to
eliminate data redundancy(repetition) and undesirable characteristics like
Insertion, Update and Deletion Anomalies. It is a multi-step process that
puts data into tabular form, removing duplicated data from the relation
tables.
This module will also discuss joins. A JOIN clause is used to combine rows
from two or more tables, based on a related column between them. It will
also tackle the ER modeling and how to create ER diagram.
VI. Module Outcomes What you will learn in this chapter: how normalization protects databases
from anomalies; rules on how to create 1NF, 2NF, 3NF and BCNF. You
will also be able to understand and create: inner join; left join; right join;
and full join; the main characteristics of entity relationship components;
how relationships between entities are defined and refined; how ERD
components affect database design and implementation.

Learning Module on IM 201


168

M3:L1 EXERCISE.
a. If a table includes a ZIP code with every address, what 3NF rule does the table break? Why?
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
______________________________
b. What data anomalies can result from including postal codes in address data? How bad are they? How can you
mitigate the problems?
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________

c. Suppose you’re writing an application to record times for dragon boat races and consider the table below.
Assume the table’s key is Heat. What 1NF, 2NF, and 3NF rules does this design violate?

__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________

Learning Module on IM 201


169

__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
____________________________________
M3:L1 Application
Create the 1st, 2nd, and 3rd normal form of the given table below. Write your answer on the space provide.

a. 1NF

b. 2NF

Learning Module on IM 201


170

c. 3NF

Learning Module on IM 201


171

Summary of the Lesson:


1. Normalization protects a database from data anomalies.
2. 1NF rules:
1. Each column must have a unique name.
• The order of the rows and columns doesn’t matter.
• Each column must have a single data type.
• No two rows can contain identical values.
• Each column must contain a single value.
• Columns cannot contain repeating groups.
3. 2NF rules:
• It is in 1NF.
• All non-key fields depend on all key fields.
4. 3NF rules:
• It is in 2NF.
• It contains no transitive dependencies. (No non-key fields depend on other non-key fields.)
5. SQL JOIN inner, left, right and outer are used to combine tables.

Learning Module on IM 201


172

M3:L1 Enrichment Activity


Create the SQL command for the below problems; use the tables below for the instance of the database.

a. SQL command to inner join table DRUG and table PRESCRIPTION.


__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________
b. SQL command to display columns “drug_name” and “pres_dosage”.
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________
c. SQL command to display all columns of tables DOCTOR, PATIENT and PRESCRIPTION.
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________
d. SQL command to display all patient names and their assigned doctors.

Learning Module on IM 201


173

__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________
e. SQL command to join tables DRUG, PATIENT and PRESCRIPTION.
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________

Learning Module on IM 201


182

M3:L2 EXERCISE.
Create the ER Diagram for each problem; use the space provided to draw your answer.
a. One EMPLOYEE is assigned to one PHONE EXTENSION.

b. Many EMPLOYEES are members of a DEPARTMENT.

c. An EMPLOYEE is assigned to an OFFICE.

d. One CARGO AIRCRAFT will serve one or more DISTRIBUTION CENTERs.

e. SYSTEMS ANALYST may be assigned to MANY PROJECTS.

M3:L2 Application
a. The physician treats the illness a PATIENT has. Many PATIENT(s) experience many TREATMENT(s).
TREATMENT(s) can include the taking of PRESCRIPTION(s). Create the ERD of the above facts. Draw your
answer on the space provided.
Tip: You should be creating a single ERD with interconnected entities.

Learning Module on IM 201


183

b. The PATRON actually makes a one or more RESERVATION. RESERVATION(s) is/are for a
CONCERT/SHOW. Create the ERD of the above facts. Draw your answer on the space provided.

Learning Module on IM 201


184

Summary of the Lesson:


1. In this chapter we presented the modeling concepts of a high-level conceptual data model, the entity–
relationship (ER) model.
2. Then we discussed the ER model concepts at the schema or “intension” level:
• Entity types and their corresponding entity sets
• Key attributes of entity types
• Value sets (domains) of attributes
3.We presented two methods for specifying the structural constraints on relationship type which are the
Cardinality ratios (1:1, 1:N, M:N)

Learning Module on IM 201


185

M3:L2 Enrichment Activity


Create the ER Diagram for each problem; use the space provided to draw your answer.
a. A MACHINE may or may not be undergoing SCHEDULED MAINTENANCE.

b. “One or many SALESPERSONs are assigned to one or more CUSTOMERs.

c. One or more EMPLOYEEs may or may not be assigned to the HOME OFFICE.

d. Many PASSENGERs are flying to many DESTINATIONs.

Learning Module on IM 201


186

M3 Assessment:
I. Define the connection of the below paired entities whether it is 1:1, 1:M or M:N based on the given
scenario. Write your answer in column connectivity.
ABC College is divided into several schools. Each school is composed of several departments. Each department
may offer courses. Each department may have many professors assigned to it. Each professor may teach up to
four classes; each class is section of course. Student may enroll in several classes.
Each department has several students. Each student has only a single major and is associated with a single
department. Each student has an advisor in his or her department. Each advisor counsels several students. The
relationship between class is taught in a room and the room in the building. Professor can only teach in one school.
Item
No. Entity Connectivity Entity
1. School Department
2. Department Student
3. Department Professor
4. Department Course
5. Course Class
6. Professor School
7. Professor Department
8. Professor Class
9. Professor Student
10. Student Class
11. Building Room
12. Room Class

I. Create the 1st, 2nd and 3rd normal form of the below table. Use the space provided below for your
answer.

1. 1NF

Learning Module on IM 201


187

2. 2NF

3. 3NF

Learning Module on IM 201


188

II. Create the INNER, LEFT and RIGHT JOIN of the below tables.

Table name: Customerx

Table name: Ordery

1. INNER JOIN
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
______________________________________________________________________

Learning Module on IM 201


189

2. LEFT JOIN
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
______________________________________________________________________
3. RIGHT JOIN
__________________________________________________________________________________________
__________________________________________________________________________________________
__________________________________________________________________________________________
______________________________________________________________________

Learning Module on IM 201

You might also like