Professional Documents
Culture Documents
Learning Outcomes
This activity encompasses activities 4A, 4B and 4C
Activity 4A
Activity Outcome: Identify the basic elements of ERD and design the ERD based on a given
scenario by using Chen’s Model.
Nena Electrical Co. Wishes to create a database with the following entities and attributes:
a. Customer, with attributes: CustomerID, Name, Email, Telephone
b. Location, with attributes: LocationID, Address, Type
c. Rate, with attributes: , RateID, RateClass, Rateperkwh
After the interviews with the owner you have come up with the following business rules:
● Customer can have one or more locations
● Each location can have one and only one customer
● Each location can have one or more rates
● Each rate may be used at many locations, or not used at a location
1. Identify all the basic elements of ERD that are involved based on the above scenario:
a) Entity and Attribute
Entity Attribute
Page 2 of 31
DFC 2083 DATABASE DESIGN
c) Identifier keys
2. Draw the E-R Diagram using Chen’s Model based on the Activity4A(1) that you have
identified.
Page 3 of 31
DFC 20203 DATABASE DESIGN
Activity 4B
Activity Outcome: Identify the basic elements of ERD and design the ERD based on a given
scenario by using Crow’s Foot.
An automobile insurance company needs to keep track of information about vehicle. The
company has to store information of customer, car and accident. Customer information is
LicenseNo, name and address. Customers can own one or more cars, where the car information
is PlateNo, model and year. A car not involved or involved in many accidents. If the car is involved
in an accident, the information that will be stored is Report_number, location and date.
1. Identify all the basic elements of ERD that are involved based on the above scenario:
Entity Attribute
b) Identifier keys
Page 4 of 31
DFC 2083 DATABASE DESIGN
2. Draw the E-R Diagram using Chen’s Model based on the Activity4B(1) that you have
identified.
Page 5 of 31
DFC 20203 DATABASE DESIGN
Activity 4C
Activity Outcome: Convert a given ERD into relational tables.
1. Convert the E-R Diagram based on the Activity 4A(2) into the relational tables.
2. Convert the E-R Diagram based on the Activity 4B(2) into the relational tables.
Page 6 of 31
DFC 2083 DATABASE DESIGN
Activity 4D
Activity outcome : Using Chen Model Notation, Draw the ERD for the given scenario below.
There are many soccer teams in Liga Super Malaysia ; each team has an ID,name,main stadium,
and which city this team belongs.Each team has many players,and each player belongs to one
team.Each player has a number,name,DOB,start year and shirt number that he uses.Teams play
matches, for each match you need to keep track the date on which the game is played, match ID
and the final result of the match.Each match has exactly three referees.For each referee have an
referee ID,name,DOB and year of experience.
(10 Marks)
Page 7 of 31
DFC 20203 DATABASE DESIGN
Activity 4E
Activity outcome : Using Crow’s Foot Model Notation, Draw the ERD for the given scenario below.
Seremban Hospital has several wards. This hospital has a few types of ward depends on types
of patients. Patient information will be recorded into file that patient number, patient name,
address, phone number, IC number, patient and group of blood patient. Each patient is treated
by a doctor at one time but one doctor can treats a number of patients. The information of doctors
recorded are : doctor ID, doctor name, address, phone no, IC no and expertise. The nurses will
be assigned to take care of the patients. Nurses in this hospital are graded based on their
experience, qualification and duration of working in the hospital.
(10 Marks)
SET 1
Page 8 of 31
DFC 2083 DATABASE DESIGN
Learning Outcomes
This activity encompasses of activities from 5A to 5D.
Activity 5A
Activity Outcome: Able to create Database, tables and manipulates tables using DDL
statements
Procedures
Step 3 : Click on SQL tab and type the SQL command(VENDOR table) as shown below.
Page 9 of 31
DFC 20203 DATABASE DESIGN
Step 7 : Type SQL command to change the P_ITEM character length from 35 to 40.
Step 8 : Type SQL command to Add attribute V_AGE into table VENDOR.
Step 9 : Type SQL command to change the data type attribute V_AGE from INT to CHAR.
ALTER TABLE VENDOR
ALTER V_AGE CHAR;
Step 10 : Type SQL command to Delete attribute V_AGE from table VENDOR.
ALTER TABLE VENDOR
DROP V_AGE;
Page 10 of 31
DFC 2083 DATABASE DESIGN
Activity 5B
Procedures:
Step 1 : Click on SQL tab and type SQL command that insert new data into PRODUCT table .
INSERT INTO PRODUCT
VALUES ( ‘JT00833’, ‘Joystick’, 6, 30.99, 25595);
Step 2 : Type the following SQL command to insert another data into PRODUCT table.
INSERT INTO PRODUCT
VALUES ( ‘KK0011’, ‘Scanner’, 12, 300.99, 21344);
Step 5 : Click on SQL tab and type SQL command to delete a data in the PRODUCT table
using the following command.
Step 6 : Click on SQL tab and type SQL command to delete a data in the PRODUCT table
using the following command.
Page 11 of 31
DFC 20203 DATABASE DESIGN
Activity 5C
Appendix B
Database : CAR
CUSTOMER
CAR_COMPONENT
CLAIM
COMPONENT_CLAIM
Page 12 of 31
DFC 2083 DATABASE DESIGN
Procedures:
Step 10 : Open the SQL Editor and type SQL command to display car number begin with D.
Step 11 : Open the SQL Editor and type SQL command to display claim ID and quantity where
claim number is CL001 and CL012.
Page 13 of 31
DFC 20203 DATABASE DESIGN
Activity 5D
Procedures:
Step 1 : Open the SQL Editor and type SQL command to find the minimum value for price
in the COMPONENT table
Step 2 : Open the SQL Editor and type SQL command to find the maximum value for
price in the COMPONENT table
Step 3 : Open the SQL Editor and type SQL command to find the average value for price
in the table COMPONENT.
SELECT AVG(price) AS AVGPRICE
FROM CAR_COMPONENT;
Step 4 : Type SQL command to find average value for quantity in the table
COMPONENT_CLAIM.
Step 5 : Open the SQL Editor and type SQL command to sum the price in the table
COMPONENT
SELECT SUM(price) AS TOTALPRICE
FROM CAR_COMPONENT;
Page 14 of 31
DFC 2083 DATABASE DESIGN
Step 6 : Type SQL command to sum the components quantity in the table
COMPONENT_CLAIM.
Step 7 : Open the SQL Editor and type SQL command to count the number of customers
SELECT COUNT(*)
FROM CAR_CLAIM
Step 9 : Open the SQL Editor and type SQL command to sum the quantity component
group by claim number.
Step 10 : Open the SQL Editor and type SQL command to find the total quantity group by
claimID which less than 1 in COMPONENT_CLAIM table.
Page 15 of 31
DFC 20203 DATABASE DESIGN
SET 2
LAB ACTIVITY 5(i): Structured Query Language (SQL)
Duration : 4 Hours
Learning Outcomes
This Activity encompasses of activities from 5(i)A to 5(i)H.
Activity 5(i)A
Activity Outcome: Create a database named BOOK DETAILS.
A database is a shared, integrated computer structure that houses a collection of end-user data
and metadata. In BOOK DETAILS database, we will use it to store AUTHOR and BOOK data.
Procedure:
Step 1: Open MySQL Workbench 5.2. Double click on ‘Local Instance MySQL’ .
Click
here.
Page 16 of 31
DFC 2083 DATABASE DESIGN
Step 4: Look at the ‘Object Browser’, where you will see BOOK_DETAILS database appears
along with other databases. Click refresh button if it did not appear.
Refresh
BOOK_DETAILS
Page 17 of 31
DFC 20203 DATABASE DESIGN
Activity 5(i)B
Activity Outcome: Create tables in BOOK_DETAILS database.
Table is a structure that will store data. In this activity, we will create two tables named
AUTHOR and BOOK to store author and book data.
USE BOOK_DETAILS;
DESC AUTHOR;
DESC BOOK;
Page 18 of 31
DFC 2083 DATABASE DESIGN
Table AUTHOR
Table BOOK
Activity 5(i)C
Activity Outcome: Create duplicate table named AUTHOR2 in BOOK_DETAILS database.
We can create a copy of existing table by using command
‘CREATE TABLE <new_table_name>
AS SELECT <column_name> FROM <existing_table_name>.
Procedures:
Page 19 of 31
DFC 20203 DATABASE DESIGN
Table AUTHOR2
Activity 5(i)D
Activity Outcome: Add column(s) in existing table.
We can add more columns by using command ALTER TABLE …ADD.
Procedures:
New columns
Page 20 of 31
DFC 2083 DATABASE DESIGN
Activity 5(i)E
Activity Outcome: Modify column(s) in existing table.
We can modify column structure by using command ALTER TABLE ...MODIFY.
Procedures:
Activity 5(i)F
Activity Outcome: Delete column(s) in existing table.
We can delete column by using command ALTER TABLE ...DROP.
Procedures:
Page 21 of 31
DFC 20203 DATABASE DESIGN
Activity 5(i)G
Procedures:
Foreign
key
Activity 5(i)H
Procedures:
Page 22 of 31
DFC 2083 DATABASE DESIGN
Learning Outcomes
This activity encompasses of activities from 5(ii)A to 5(ii)C.
Activity 5(ii)A
Activity Outcome: Add record(s) in existing table.
We can add record(s) by using command INSERT INTO.
Procedures:
Page 23 of 31
DFC 20203 DATABASE DESIGN
Activity 5(ii)B
Procedures:
UPDATE AUTHOR
SET EMAIL = ‘betty_nl@yahoo.com’
WHERE AUTHOR_ID = ‘A01’;
Step 2: Type SELECT * FROM AUTHOR; and click button , to see the changes.
Activity 5(ii)C
Procedures:
Step 2: Type SELECT * FROM AUTHOR; and click button , to see the changes.
Step 3: You can also use TRUNCATE to delete entire records from a table.
TRUNCATE BOOK;
Step 4: Type SELECT * FROM AUTHOR; and click button , to see the changes.
Page 24 of 31
DFC 2083 DATABASE DESIGN
Learning Outcomes
This activity encompasses of activities from 5(iii)A to 5(iii)B.
Activity 5(iii)A
Activity Outcome: Retrieve data from table by using comparison and logical operator.
We can use various comparison and logical operators such as =, <, >, IN, LIKE to retrieve data
from a database.
Procedures:
Step 1: Open MySQL Workbench 5.2. Double click on ‘Local Instance MySQL’ .
USE SAKILA;
Step 3: Type the following command to display all records from table ACTOR.
Click button .
Step 4: Type the following command to display only first name and last name columns.
Click button .
Step 5: Type the following command to display record for actor whose id is A01.
Click button .
Page 25 of 31
DFC 20203 DATABASE DESIGN
Step 6: Type the following command to display record from table FILM where its rating is PG
and length is more than 180.
Click button .
Step 7: Type the following command to display record from table FILM where its length is
between 100 to 120.
Click button .
Step 8: Type the following command to display record from table ADDRESS where its district is
in Hiroshima, Nagano or Osaka.
Click button .
Step 9: Type the following command to display record from table ACTOR where his/her first
name start with R.
Click button .
Step 10: Type the following command to display record from table ACTOR where the second
letter in his/her name is R.
Click button .
Page 26 of 31
DFC 2083 DATABASE DESIGN
Activity 5(iii)B
Activity Outcome: Sort results.
We can sort the order of data by using command ORDER BY and put it at the of SQL
statement. Default order is ascending (ASC) but it can also be sorted in descending (DESC)
order.
Procedures:
Page 27 of 31
DFC 20203 DATABASE DESIGN
Learning Outcomes
This activity encompasses of activities from 5(iv)A to 5(iv)D.
Activity 5(iv)A
Activity Outcome: Retrieve data from table by using aggregate functions.
We can use aggregate functions such as AVG, SUM, COUNT, MIN & MAX to retrieve data from
a database.
Procedures:
Step 1: Open MySQL Workbench 5.2. Double click on ‘Local Instance MySQL’ .
USE SAKILA;
SELECT AVG(AMOUNT)
FROM PAYMENT;
SELECT COUNT(ACTOR_ID)
FROM ACTOR;
Page 28 of 31
DFC 2083 DATABASE DESIGN
SELECT SUM(AMOUNT)
FROM PAYMENT;
Activity 5(iv)B
Activity Outcome: Round off numeric values.
Procedures:
SELECT ROUND(AVG(AMOUNT), 2)
FROM PAYMENT;
Activity 5(iv)C
Activity Outcome: Use GROUP BY to group results.
We can use GROUP BY to group the results. Usually it is used in conjunction with the
aggregate functions to group the result-set by one or more columns.
Procedures:
Page 29 of 31
DFC 20203 DATABASE DESIGN
Activity 5(iv)D
Activity Outcome: Use HAVING to filter data.
HAVING is used to filter data based on the group functions (ex. SUM). It is similar to WHERE
condition but used with group functions. Group functions cannot be used in WHERE clause.
Procedures:
Page 30 of 31
DFC 2083 DATABASE DESIGN
Page 31 of 31