<PBA Web - Databases - Exercise
ZiBaT => Peter Levinsky => PBA-Database => exercise
Trigger
Updated : 2018-03-16

Background

What is a trigger see wiki - database trigger
SERVER chap 15, p. 537-559

Reference Triggers :
mssql https://docs.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql
examples: https://www.mssqltips.com/sqlservertutorial/2911/working-with-triggers/ 

mysql https://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html
examples: http://www.mysqltutorial.org/create-the-first-trigger-in-mysql.aspx

Triggers:
http://www.sqlteam.com/article/an-introduction-to-triggers-part-i
http://www.sqlteam.com/article/an-introduction-to-triggers-part-ii

 

Previous exercises (basis for this exercise) PetersPanSQLexercise1.htm

Assignment 1 Control validity of data

For the 'RestaurantTable' table, make a trigger to control the Seats before insert a row into the table.

The Seats must be between 0 and 12 otherwise it should not be inserted.

Could you do this in another way? if yes how?

 

Assignment 2 Kind of Trace

Make trigger that print the information that is inserted in the Booking table

First just print it on the screen. (e.g print ' ... the text .... ' )

 

Assignment 3 Make A booking History logfile

Make trigger that Make a new row in a new table 'OldBookings' if a Booking is deleted

Create a new table 'OldBooking' having the information of a Booking but also a new field the date and time of the deletion.

 

Assignment 4 Control validity of data2

For the Booking table

Let say a business rule tells a Customer can not have more than 10 bookings.

Make a trigger to check, that the number of bookings of the Customer do not exceed 10 otherwise it should not be inserted.

 

Extra A : Auto filling of field informations

For the Booking Table modify the table to have DayAndTimeOfBooking.

When insert make a trigger to insert current day and time of the booking.