Clinic 3 Answer
Clinic 3 Answer
1) Write the SQL statement to insert a new customer. The details of the customer is as follows:
a. customer_id: 1005
b. first_name: Elle
c. last_name: Low
d. address_id: 103
e. active: TRUE
f. create_date: current date and time
2) Write the SQL Statement to update this new customer’s active status to FALSE.
UPDATE customer
SET active = false
WHERE customer_id = 1005;
DELETE
FROM customer
WHERE customer_id = 1005;
4) Write the SQL statement to display the number of rental of each country.
The output counts the number of occurrence of the customers based on the first letter of
their last name. Filter the count to display only the letters with more than 50 occurrences
with the highest occurrence displayed on the top.
Each film can only be loaned for one week (7 days). The output counts the number of late
return of each customer. [hint: datediff(return_date,rental_date) > 7]
Display the customer with the highest number of late return on the top.
Section B - ERD
1) Which of the followings can be found in an ERD?
a. Tables and attributes
b. Relationships
c. Test Data
d. Constraints
3) If two tables have many-to-many relationship, what table is needed to represent the
relationship? What type of primary can be used in this table?
a. Resolving table
b. COMPOUND primary key / SURROGATE primary key
student project
Section C – Normalisation
1) State the rules of the three normal forms.
a. First normal form (1NF)
i. Every table has a unique primary key
ii. Remove derived columns
iii. No repeating groups
b. Second normal form (2NF)
i. Must be in 1NF
ii. No partial dependencies (applies only to compound keys)
c. Third normal form (3NF)
i. Must be in 2NF
ii. No transitive dependencies (column relies on column that is defined by
primary key)
Question
No Question Student ID Name Diploma Diploma Name Answer
1 Which 120001 John DBA Diploma in Business Application E-Canteen
canteen do
you like Diploma in Business Information Food
best? 120002 Kelly DBIS System Haven
120003 Loki DBA Diploma in Business Application E-Canteen
120004 Mary DBA Diploma in Business Application E-Canteen
Diploma in Information Food
120005 Norman DIT Technology Haven
Diploma in Information
120006 Osman DIT Technology Kou Fu
2 Is the food 120001 John DBA Diploma in Business Application Yes
expensive? Diploma in Business Information
120002 Kelly DBIS System No
120003 Loki DBA Diploma in Business Application No
120004 Mary DBA Diploma in Business Application Yes
Diploma in Information
120005 Norman DIT Technology No
Diploma in Information
120006 Osman DIT Technology Yes
1NF
“question” question_no, question
“answer” question_no, student_id, name, diploma, diploma_name, answer
2NF
“question” question_no, question
“answer” question_no, student_id, answer
“student” student_id, name, diploma, diploma_code
3NF
“question” question_no, question
“answer” question_no, student_id, answer
“student” student_id, name, diploma_code
“diploma” diploma_code, diploma_name
OR
3NF
“question” question_no, question
“answer” question_no, student_id, answer_id
“answer” answer_id, answer
“student” student_id, name, diploma_code
“diploma” diploma_code, diploma_name
Changes made to the database, since the transaction began, are persisted.
4) What happen when a “ROLLBACK” command is given?
Changes made to the database, since the transaction began, are un-done.
5) The COMMIT and ROLLBACK commands ensure which component of ACID and CIA?
6) John withdrew $100 at an ATM machine. The next day, he discovered that instead of $100,
$110 was deducted from his account. Which component of ACID is violated?
Consistency is violated.
7) John went to the bank to enquiry on the incorrect deduction. The bank manager told him
that the bank’s ATM system was being manipulated to deduct 10% more. Which component
of CIA has the system failed?
1) Whenever 3 numbers (<1000) are inserted into the ‘cal_average’ table, a trigger will be fired
to calculate and store the average. Fill in the blanks below to complete the function and
trigger.
RETURNS DECIMAL(6,3)
BEGIN
RETURN ( (para_num1 + para_num2 + para_num3) / 3.0);
END$$