You are on page 1of 38

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


Lesson 1. Databases and Database Users
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, metadata, and transaction-processing application.
Data – are attributes or information, typically mathematical, that are gathered through
perception. In a more specialized sense, information are a lot of estimations of subjective or
quantitative factors around at least one people or articles, while a datum is a solitary estimation
of a solitary variable.
Database – is a collection of related data
DBMS – is a computerized system that enables users to create and maintain a database. The
general-purpose software system that facilitates the processes of defining, constructing,
manipulating, and sharing databases among various users and applications.
Database System –
Database Catalog – contains information such as the structure of each file, the type and storage
format of each data item, and various constraints on the data
Program data Independence – refers to the coupling of data stored in files and the specific
programs required to update and maintain those files such that changes in programs require
changes to the data. In a tradition file environment, any change in a software program could
require a change in the data accessed by that program.
User View – It is a subset of the external schema for querying the course-material knowledge
base; the subset is usually defined based on the corresponding user profile for extracting relevant
data and information.
DBA –is a specialized computer systems administrator who maintains a successful database
environment by directing or performing all related activities to keep the data secure.
End User – basically those people whose jobs require access to the database for querying,
updating and generating reports.
Canned Transaction – are standard types of queries and updates which are frequently used by
Naive end users to constantly querying and updating database. These are the transactions that are
carefully programmed and tested in advance.
Deductive database System – is a database system that can make deductions based on rules and
facts stored in the deductive database.
Persistent Object – is an object that has been assigned a storage location in a federated database.
Metadata – information stored in the catalog
Transaction processing application- systems consist of computer hardware and software hosting
a transaction oriented application that performs the routine transactions necessary to conduct
business.
b. What four main types of actions involve databases? Briefly discuss each.
Defining a database: It incorporates the information types, structures, and limitations of the
information need to store in the data set. The data set illustrative data is additionally put away by
the DBMS as an information base inventory or word reference; it is called metadata.
Constructing the database: It is the process of data storing on some storage medium that is
maintained by the DBMS.
Manipulating a database: It incorporates capacities, for example, recover the information base by
utilizing inquiry, refreshing the information base to reflect changes in the framework, and
produce reports from the information.
Sharing a database: It allows multiple users and programs to access the database simultaneously
c. Discuss the main characteristics of the database approach and how it differs from traditional
file systems.
In database approach, a single repository of data is maintained that is defined once and then
accessed by many users. The fundamental characteristic of database approach is that the database
system not only contains data’s but it contains complete definition or description of the database
structure and constraints.But in traditional file processing system the application is developed for
a specific purpose and they will access specific database only.
d. Discuss the capabilities that should be provided by a DBMS.
Functions of DBMS vary greatly, general-purpose DBMS features and capabilities should
include: a user accessible catalog describing metadata, DBMS library management system, data
abstraction and independence, data security, logging and auditing of activity, support for
concurrency and transactions, support for authorization of access, access support from remote
locations, DBMS data recovery support in the event of damage, and enforcement of constraints
to ensure the data follows certain rules.
e. Discuss the differences between database systems and information retrieval systems.
Database management system can be regarded as a store house of information. It is a centralized
repository where raw data would be organized as tables with each column representing an
attribute of the data while information retrieval system refers to an overall system which is
capable of searching and providing useful information from a data repository based one or more
combinations of search conditions (queries). It is a more generic term and can mean lots of
things other than a conventional DBMS alone.
M1:L1 Application
a. Cite some examples of integrity constraints that you think can apply to the database shown in
Figure 1.2.
KEY CONSTRAINTS
DOMAIN CONSTRAINTS
REFERENTIAL INTEGRITY CONSTRAINTS
b. Give examples of systems in which it may make sense to use traditional file processing instead
of a database approach.
Library record, shown a diagram that shows program and data independency.
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.
STUDENT (major)
COURSE (course_number), (department)
SECTION (course_number)
PREREQUISITE (course-number), (pre requisite_number)
b. Give a one sentence description of each of the tasks you listed for question number 1.
List of names of students, took the course and the department, and section the got.
Lesson 2. Database System Concepts and Architecture
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.
A data model—a collection of concepts that can be used to describe the structure of a database—
provides the
necessary means to achieve this abstraction.
database schema, which is specified during database design and is not
expected to change frequently
The data in the database at a particular moment in time is
called a database state orThe internal level has an internal schema, which describes the physical
storage structure of the database.

The internal schema uses a physical data model and describes the complete details of data
storage and access paths
for the database. snapshot. It is also called the current set of occurrences or instances in the
database.
The conceptual level has a conceptual schema, which describes the structure of the whole
database for a
community of users. The conceptual schema hides the details of physical storage structures and
concentrates on
describing entities, data types, relationships, user operations, and constraints.
The external or view level includes a number of external schemas or user views. Each external
schema describes
the part of the database that a particular user group is interested in and hides the rest of the
database from that
user group.
data independence, which can be
defined as the capacity to change the schema at one level of a database system without having to
change the
schema at the next higher level.
(SDL), is used to specify
the internal schema
a set of operations or a language called the data manipulation language (DML)
(VDL), to specify user views and their
mappings to the conceptual schema,
The catalog stores many other types of information that are needed by the DBMS modules,
which can 6then look up the catalog information as needed
Many Web applications use an architecture called the three-tier architecture, which adds an
intermediate layer
between the client and the database server, as illustrated in Figure 2.7(a).
N-tier architecture is also called multi-tier architecture because the software is engineered to
have the processing, data management, and presentation functions physically and logically
separated

b. What is the difference between logical data independence and physical data independence?
Which one is harder to achieve? Why?
Physical data independence is basically used to separate conceptual levels from the
internal/physical levels while logical data independence is used to change the conceptual scheme
without changing the external views and external API. And logical is the harder to achieve
because it only depends on the logical structure.

c. What is the difference between the two tier and three-tier client/server architecture.
2-tier architecture is client server application. 3-tier architecture is web based application.

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?
2 tier architecture because the client can directly communicate with the database at the server
side, it just like the single tier but I must preffer 2nd tier because it was upgraded and 3rd is not my
prior because the client hard to communicate to the database of it.
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.
-COURSE TABLE, COURSE NUMBER COLUMN MUST BE UNIQUE
-SECTION TABLE, SECTION IDENTIFIER COLUMN MUST BE UNIQUE
-GRADE REPORT TABLE, STUDENT NUMBERER AND SECTION INDENTIFEIR MUST
UNIQUE
-PREREQUISITE TABLE, COURSE NUMBER AND PREREQUISITE NUMBER MUST BE
UNIQUE.
Lesson 3. Introduction to SQL
M1:L3 EXERCISE.
a. Write the correct SQL statement to create a new database called ccc;
CREATE DATABASE ccc;
b. SQL statement creates a full back up of the existing database "ccc" to file path “D:\backups\”
with file name “cccdb”:
BACKUP DATABASE ccc
TO DISK = 'D:\backups\cccdb.bak';

c. SQL statement to use database ccc.


USE ccc;
d. Write the correct SQL statement to create a new table called student. With the following
columns and datatypes:
CREATE TABLE student (
Student ID int,
Last Name varchar (255)
First Name varchar (255)
Address varchar (255)
);
e. SQL statement to add "course" column with datatype and size varchar(150) to the "student"
table:
ALTER TABLE student ADD course size varchar (150);
f. SQL statement to drop "course" column in "student" table:
ALTER TABLE student
DROP COLUMN course;
g. SQL statement to drop the existing database "ccc".
DROP DATABASE ccc;
h. SQL statement to show all databases.
SHOW DATABASE ccc;

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.


CREATE DATABASE abcDB;
2. SQL statement to show all databases;
SHOW DATABASE abcDB;
3. SQL statement to use your newly created database for company ABC.
USE DATABASE abcDB;
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.
CREATE TABLE worker (
Worker id int (10),
First name char (25),
Last name char (25),

Salary int (15),


Joining date datetime,
Department char (25)
);
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.
CREATE DATABASE defDB;
2. SQL statement to show all databases;
SHOW DATABASE defDB;
3. SQL statement to use your newly created database for company DEF.
USE DATABASE defDB;
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.
CREATE TABLE title (
Worker reference id – int(10),
Worker title- char(25),
Affected from – datetime
);
Note: datetime do not have size

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.
______ DBD __________1. Conducting data backups
______ DBD __________2. Assessing database performance
______ DBA __________3. Modifying database structure if needed
______ DBD __________4. Restoring lost data
______ DBA __________5. communicate with all prospective database users
______ DBA __________6. Debugging programs or installing patches
______ DBD __________7. authorizing access to the database
______ DBD __________8. acquiring software
______ DBD __________9. purchasing hardware resources as needed
______ DBA __________10. responsible for identifying the data to be stored in the database
______ DBA __________11. choosing appropriate structures to represent and store this data
______ DBA __________12. implement the database design
______ DBD __________13. tune database performance
______ DBD __________14. install the database server software
______ DBD __________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.

CREATE SCHEMA transcript (


Student_name char (255),
Course_number varchar(255),
Grade_char (3),
Semester_char (20),
Year int (10),
Section_id int (255));
CREATE SCHEMA course_ prerequisite(
Course_name char (255),
Course_number varchar(255),
Prerequisite varchar (255));
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;
CREATE DATABASE teashopDB;
2. SQL statement creates a full back up of the existing database " teashop " to file path “D:\
backup\” with file name “teashop_db”:
BACKUP DATABASE teashopDB
TO DISK = ‘D:\backup\teashopDB’;
3. SQL statement to use database teashop.
USE teashop;
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)

CREATE TABLE cust (


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:
ALTER TABLE students
ADD varchar(250);
6. SQL statement to drop "course" column in "student" table:
ALTER TABLE students
DROP course;
7. SQL statement to drop the existing database "teashop".
DROP DATABASE teashopDB;
8. SQL statement to show all databases.
SHOW DATABASE DB;
Lesson1. SQL Commands
M2:L1 EXERCISE.
Write false if the statement is true otherwise true. Write your answer on the space provided
before each number.
____ false ______________a. The WHERE clause is used to extract only those records that
fulfill a specified condition.
____ false ______________b. SQL requires single quotes around text values (most database
systems will also allow double quotes).
____ false ______________c. The AND operator displays a record if all the conditions separated
by AND is TRUE.
____ false ______________d. The OR operator displays a record if any of the conditions
separated by OR is TRUE.
____ false ______________e. The NOT operator displays a record if the condition(s) is NOT
TRUE.
___ false _______________f. The COUNT() function returns the number of rows that matches
a specified criteria.
____ false ______________g. The AVG() function returns the average value of a numeric
column.
___ false ____ _________h. The SUM() function returns the total sum of a numeric column.
___ false ____ __________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.
____false _____________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.
Name: Company_ABC
DB Table: Employee

EMP_id EMP_name EMP_sex EMP_add EMP_byear EMP_hdate EMP_basicpay

1 John M San Pablo 1990 2009 25000


City

2 Eve F San Pablo 1994 2011 24000


City

3 Matt M Calamba 1992 2005 30000


City

4 Mary F Calamba 1987 2002 35000


City

1. SQL command to create database Company_ABC.

CREATE DATABASE company_abcDB;

2. SQL command to create table Employee.

CREATE TABLE worker (


Emp id int (10),
First name char (25),
Add char(255),
Sex char (10),
Byear int (10),
Hdate in (10),
Basic pay int (25),
);
3. SQL command to insert employee 1.

INSERT INTO employee (id, name, sex, add, byear, hdate, basicpay)
VALUES (‘1’, ‘John’, ‘m’, ‘sanpablo city’,’ 1990’, ‘2009’, ‘25000’);

4. SQL command to insert employee 2.

INSERT INTO employee (id, name, sex, add, byear, hdate, basicpay)
VALUES (‘2’, ‘Eve’, ‘f’, ‘sanpablo city’,’ 1994’, ‘2011’, ‘24000’);

5. SQL command to insert employee 3.

INSERT INTO employee (id, name, sex, add, byear, hdate, basicpay)
VALUES (‘3’, ‘Matt’, ‘m’, ‘calamba city’,’ 1992’, ‘2005’, ‘30000’);

6. SQL command to insert employee 4.

INSERT INTO employee (id, name, sex, add, byear, hdate, basicpay)
VALUES (‘4’, ‘Mary’, ‘m’, ‘calamba city’,’ 1987’, ‘2002’, ‘35000’);

7. SQL command to get the sum of basic pay of all employees.

SELECT SUM (emp_basicpay)


FROM employee;

8. SQL command to count all male employees residing at San Pablo City.

SELECT COUNT (case when emp_sex ‘m’ then 1 end)


FROM employee
WHERE emp_add = sanpablo city;

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.

SELECT COUNT (case when emp_sex ‘f’ then 1 end)


FROM employee
WHERE emp_add = calamba city;

b. SQL command to get the age of employee 2.

SELECT Emp_ID
Datediff (yy,birthdate,getdate()) as AGE
FROM Employee
WHERE Emp_id=’2’;

c. SQL command to count employees that were hired from 2000 to 2010 and currently residing
at San Pablo City.

SELECT COUNT (case when emp_hyear ‘2000’<=10’ then 1 end)


FROM employee
WHERE emp_add = sanpablo city;

d. SQL command to show all databases.

SHOW DATABASE employeeDB;

e. SQL command to show all tables.

SHOW TABLES;
Lesson 2. Relational Model

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:

Student number, student name and student phone

b. Superkeys in table subject:

Student number and Subject instructors

c. Candidate keys in all tables:

all of the tables


Application

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:

ProfI SubjectCode
D

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 Subject Code

2015123 Jenny Brgy. 1 BSIT IT101

2015124 Jenny Brgy. 2 BSIT IT101

2015125 Jenny Brgy. 1 BSCS CS101


CS101

2015126 Jean Brgy. 1 BSCS IT101

2015127 Veronica Brgy. 1 BSIT CS101

2015128 Sean Brgy. 2 BSCS IS101

2015129 Dave Brgy. 3 BSIS IS101

2015130 Mae Brgy. 4 BSIS IS101

Table: subject

SubjectCode SubjectName ProfID

IT101 Intro to IT 103

CS101 Intro to CS 101

IS101 Intro to IS 102

Table: prof

ProfID ProfName Department

101 John CS

102 Smith IS
103 Robert IT

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:

student number and subject number

b. Composite key in table enroll.

Student number

c. Secondary keys in table student and subject.

Subject name and subject number

c. Foreign key in table student.

Student number, student name, student phone and subject number

M2 Assessment:

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

_A_______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

_A_______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

_C_______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

_C_______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

_A_______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

_F_______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

_D_______7. A minimal super key.

a. Foreign Key b. Primary Key c. Super Key d. Candidate Key e. Alternate Key f. Surrogate Key

_B_______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'

_G_______9. Which SQL statement is used to extract data from a database?

d. EXTRACT e. GET f. OPEN g. SELECT

_I_______10. Which SQL statement is used to update data in a database?

h. MODIFY i. UPDATE j. SAVE AS k. SAVE

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


l. COLLAPSE m. REMOVE n. DELETE

_Q_______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

_Z_______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

_E_______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

_H_______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'

_O_______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'

_C_______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'

_G_______18. Which SQL statement is used to return only different values?

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


_T_______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')
_E_______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')
_V_______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
_P_______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
]

1. SQL statement to select all employees with an Fname starting with "j":
SELECT*FROM employee
WHERE Fname LIKE ‘j%’;

2. SQL statement to select all employees with an Lname ending with "g":
SELECT*FROM employee
WHERE Lname LIKE ‘%g’;

3. SQL statement to select all employees with an Address that have "as" in any position:
SELECT*FROM employee
WHERE address LIKE ‘%as%’;

4. SQL statement to select all employees with an Address that have "e" in the second position:
SELECT*FROM employee
WHERE address LIKE ‘_e%’;
d. SQL statement to select all employees with an Fname that starts with "b" and are at least 3
characters in length:
SELECT*FROM employee
WHERE fname LIKE ‘b__%’;
e. SQL statement to select all employees with an Fname that starts with "b" and ends with "e":
SELECT*FROM employee
WHERE fname LIKE ‘b%e’;

f. SQL statement to select all employees with an Address that does NOT start with "f":
SELECT*FROM employee
WHERE address NOT LIKE ‘f%’;

8. SQL statement to select all employees with an Fname starting with "e":
SELECT*FROM employee
WHERE Fname LIKE ‘e%’;
9. SQL statement to select all employees with an Lname ending with "c":
SELECT*FROM employee
WHERE Lname LIKE ‘%c’;
10. SQL statement to select all employees with an Address that have "if" in any position:
SELECT*FROM employee
WHERE address LIKE ‘%if%’;
11. SQL statement to select all
employees with an Address that have "t" in the second position:
SELECT*FROM employee
WHERE address LIKE ‘_t%’;
12. SQL statement to select all employees with an Fname that starts with "c" and are at least 3
characters in length:
SELECT*FROM employee
WHERE Fname LIKE ‘ if%’;

13. SQL statement to select all employees with an Fname that starts with "w" and ends with "e":
SELECT*FROM employee
WHERE Fname LIKE ‘w%e’;
14. SQL statement to select all employees with an Address that does NOT start with "k":
SELECT*FROM employee
WHERE address NOT LIKE ‘k%’;
15. SQL statement to display distinct values of SSN of all male employees.
SELECT DISTINCT super_ssn
FROM employee;
WHERE sex=male;

16. SQL statement to display distinct values of SSN of all female employees.
SELECT DISTINCT super_ssn
FROM employee;
WHERE sex = female;
17. SQL statement to display distinct values of SSN of all employees.
SELECT DISTINCT super_ssn
FROM employee;
18. SQL statement to display the total salary of all employees.
SELECT SUM(DISTINCT salary) AS "Total Salary" FROM employees;
19. SQL statement to count all employees.
SELECT COUNT (*)
FROM employee;
20. SQL statement to count all female and male employees.
SELECT TITLE,COUNT (CASE WHEN Sex='M' THEN 1 END) as 'Malecount',COUNT
(CASE WHEN Sex='F' THEN 1 END) as 'feMalecount',COUNT(*) FROM EMPLOYEE Group
by TITLE

MODULE 3
Lesson 1. Database Normalization and SQL Join
M3:L1 EXERCISE.
a. If a table includes a ZIP code with every address, what 3NF rule does the table break? Why?
Each column in the customer table is dependent on the primary key. Also, the columns don’t
rely on one another for values. Their only dependency is on the primary key.
b. What data anomalies can result from including postal codes in address data? How bad are
they? How can you mitigate the problems?
In order for our model to be in third normal form, we need to remove the transitive
dependencies.
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?
______________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________t
THE COLUMN IN THE TABLE MUST HAVE A UNQIE NAME FOR THE INDICATOR OF
WHAT IS INSIDE THE SPECIFICC BECAUSE THE IDINCATOR HAVE THE SAME
NAME READERS OF THE DATABASE MAYBE CONFUSE IN WHAT WILL BE THE
SPECIFIC COLUMN YOU ARE PERTAINING FOR.
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
Student student Address Course Subject Subject Name Prof ID Prof Name
ID Name Code
2015123 Jenny Brgy. 1 BSIT IT101 Intro to IT 101 John
2015124 Albert Brgy. 2 BSIT IT101 Intro to IT 101 John
2015125 Simon Brgy. 1 BSCS CS101 Intro to CS 102 Smith
2015126 Jean Brgy. 1 BSIT IT102 Intro to Net 104 Paul
2015127 Veronic Brgy. 1 BSIT IT102 Intro to Net 104 Paul
a
2015128 Sean Brgy. 2 BSCS CS101 Intro to CS 102 Smith
2015129 Dave Brgy. 3 BSCS CS102 Intro to PL 103 Robert
2015130 Mae Brgy.4 BSCS CS102 Intro to PL 103 Robert
b. 2NF
STUDENT_DETAIL table:
StudentID studentName Address Course

2015123 Jenny Brgy. 1 BSIT


2015124 Albert Brgy. 2 BSIT
2015125 Simon Brgy. 1 BSCS
2015126 Jean Brgy. 1 BSIT
2015127 Veronica Brgy. 1 BSIT
2015128 Sean Brgy. 2 BSCS
2015129 Dave Brgy. 3 BSCS
2015130 Mae Brgy.4 BSCS

STUDENT_SUBJECT table:
SubjectCode SubjectName

IT101 Intro to IT
IT101 Intro to IT
CS101 Intro to CS
IT102 Intro to Net
IT102 Intro to Net
CS101 Intro to CS
CS102 Intro to PL
CS102 Intro to PL

PROFESSOR_DETAIL table:
ProfID ProfName
101 John

101 John

102 Smith

104 Paul

104 Paul

102 Smith

103 Robert

103 Robert

c. 3NF
TABLE_SUBJECTCODE_DETAIL
SubjectCode SubjectName ProfID ProfName

IT101 Intro to IT 101 John


IT101 Intro to IT 101 John
CS101 Intro to CS 102 Smith
IT102 Intro to Net 104 Paul
IT102 Intro to Net 104 Paul
CS101 Intro to CS 102 Smith
CS102 Intro to PL 103 Robert
CS102 Intro to PL 103 Robert

TABLE_SUBJECTCODE
Subjec SubjectNa ProfID
t Code me

IT101 Intro to IT 101

IT101 Intro to IT 101

CS101 Intro to CS 102

IT102 Intro to Net 104

IT102 Intro to Net 104

CS101 Intro to CS 102

CS102 Intro to PL 103

CS102 Intro to PL 103

TABLE_PROFID_DETAIL
ProfID ProfNAme
101 John
102 Smith
103 Robert
104 Paul

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.
SELECT drug. Drug code, Prescription. Drug code
FROM drug
INNER JOIN Prescription
ON drug. Drug code = Prescription. Drug code;
b. SQL command to display columns “drug_name” and “pres_dosage”.
SELECT drug name, pres dosage FROM drug, prescription;
c. SQL command to display all columns of tables DOCTOR, PATIENT and
PRESCRIPTION.
Select doc id,doc name, doc specialization,
from doctor,
inner join prescription, patient;
d. SQL command to display all patient names and their assigned doctors.
SELECT* FROM doctor,patient,
WHERE patient = doctor;
e. SQL command to join tables DRUG, PATIENT and PRESCRIPTION.
SELECT d code, d name, d price, d id, pat dob, pat sex, pat num, p dos, p date
FROM drug
INNER JOIN prescription,
ON d.d code = p.d code,
INNER JOIN patient,
ON pa.pat num = p.pat num;
Lesson 2. Entity-Relationship Model
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.
EMPLOYEE PHONE EXTENSION
b. Many EMPLOYEES are members of a DEPARTMENT.
EMPLOYEES DEPARTMENT
c. An EMPLOYEE is assigned to an OFFICE.
EMPLOYEE OFFICE
d. One CARGO AIRCRAFT will serve one or more DISTRIBUTION CENTERs.
CARGO AIRCRAFT DISTRIBUTION CENTER
e. SYSTEMS ANALYST may be assigned to MANY PROJECTS.
CARGO AIRCRAFT DISTRIBUTION CENTER
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.

PHYSICIAN PATIENT

TREATMENT

PRESCIPTION

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.
PATRON RESERVATION

CONCERT/
SHOW

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.

MACHINE SCHEDULED
MAINTENANCE

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

SALESPERSON(S) CUSTOMER(S)

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

EMPLOYEE(S) HOME OFFICE

d. Many PASSENGERs are flying to many DESTINATIONs.

PASSENGER DESTINATIONS
S

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
Student_I Studen Cours Subject_Cod Subject_Nam Grad Prelim_Grad Midterm_Grad Final_Grad Subject_Proffes
D t e e e e ID e e e or
Name
101 Dela BSIT 201 Computer 301 90 85 90 De Mesa
Cruz, Security
Juan
101 Dela BSIT 202 Web Design 302 88 88 90 De Gallo
Cruz,
Juan
101 Dela BSIT 203 IRM 303 78 87 91 Del Mundo
Cruz,
Juan
101 Dela BSIT 204 Intro to 304 93 90 87 De Vera
Cruz, Philosophy
Juan
102 Pabor, BSIT 201 Computer 305 77 79 80 De Mesa
Grace Security
102 Pabor, BSIT 202 Web Design 306 84 78 80 De Gallo
Grace
102 Pabor, BSIT 203 IRM 307 56 78 75 Del Mundo
Grace
102 Pabor, BSIT 204 Intro to 308 74 78 79 De Vera
Grace Philosophy

2. 2NF
Student_Details Table:

Student_ID Student Name Course

101 Dela Cruz, Juan BSIT


101 Dela Cruz, Juan BSIT

101 Dela Cruz, Juan BSIT

101 Dela Cruz, Juan BSIT

102 Pabor, Grace BSIT

102 Pabor, Grace BSIT

102 Pabor, Grace BSIT

102 Pabor, Grace BSIT

Subject_Details Table:

Subject_Code Subject_Name Subject_Proffesor

201 Computer Security De Mesa

202 Web Design De Gallo

203 IRM Del Mundo

204 Intro to Philosophy De Vera

201 Computer Security De Mesa

202 Web Design De Gallo

203 IRM Del Mundo

204 Intro to Philosophy De Vera

StudentGrade_Details Table:
Grade ID Prelim_Grade Midterm_Grade Final_Grade

301 90 85 90

302 88 88 90

303 78 87 91

304 93 90 87

305 77 79 80

306 84 78 80
307 56 78 75

308 74 78 79

3. 3NF\
II. Create the INNER, LEFT and RIGHT JOIN of the below tables.
Table name: Customerx

Table name: Ordery

1. INNER JOIN
SELECT Customerx.Customerx, Ordery.OrderID
FROM Customerx
INNER JOIN Ordery ON Customerx.OrderID = Ordery.OrderID;
2. LEFT JOIN
SELECT Customerx.customerName, Ordery.OrderID
FROM Customerx
LEFT JOIN Ordery ON Customerx.CustomerID = Ordery.customerID
3. RIGHT JOIN
SELECT Ordery.OrderID, Customerx.customerName
FROM Ordery
RIGHT JOIN Customerx ON Ordery.customerID = Customerx.customerID
ORDER BY Ordery.OrderID

You might also like