You are on page 1of 2

KT24603 Database

Lab 5
Advance SQL Statements

Lab tutorial on Triggers and Views

Answer all questions.

PET(id, name, type, breed, ownerIC, dietRemark)


OWNER(ic, name, address, phoneNo, points)
BRANCH(id, city, capacity)
BOARDING(id, petID, branchID, dateIn, dateOut)

Triggers

In short, trigger fires an action when an operation is executed.

1. Create a trigger named ins_branch that capitalise the city name upon each new
branch record.

2. Create a trigger named free_points that set the points to 100 for each new owner.

3. Enough spaces are needed to ensure that animals can roam freely when being
boarded. Create a trigger named spare_capacity that minus 10 from the total
capacity for all existing branch.

Note: As we don’t update IDs and we are triggering the capacity. You can do updates
on the city name perhaps.

4. Using BEGIN … END to define a trigger that executes multiple statements. Use
DELIMETER to separate the statements.

Create a trigger named bonus_points that give extra points to each existing owner.
The extra points is as follow:

Current Points Bonus Points


0 100
>= 100 500
>= 500 1000

5. Display all triggers in the database.


View

Views can be said as virtual table. It eases time re-running the same queries again and again.

1. Create a view named likas_people to display all owners from Likas. Sample query
output is as below.

2. Create a view named likas_boarding to display all boarding made for the Likas
branch. Sample query output is as below.

3. Create a view named full_likas_boarding to display further details on all


boarding made for the Likas branch. Sample query output is as below.

4. Create a view name pet_boardings that display all pets, and any boardings they
might have. Sample query output is as below.

You might also like