Database Events
Database Essentials - Part 12
Division 1
Forward: In this tutorial we learn about database events. An event is an action that depends on time.
By: Chrysanthus Date Published: 4 Aug 2012
Introduction
Note: If you cannot see the code or if you think anything is missing (broken link, image absent), just contact me at forchatrans@yahoo.com. That is, contact me for the slightest problem you have about what you are reading.
Open the following link in a new Tab Window so that you can toggle between the new tab and this tab as you read (link below).
The opened tab window shows three events in a database. I assume that you have read the previous parts of the series so as to easily understand this tutorial.
Illustration
The figure in the web page opened, is for a database of a small supermarket. The sale class is shown; the Product class also called the Inventory class is shown; the Order class is also shown.
The table of products has a set of columns (not shown). One of the columns has the title, Reorder Level (not shown). So for each product (row) there is a reorder level. This is a particular number. As you are selling any product, the quantity of the product in the store (inventory) is reducing. The number will be reducing until it reaches a reorder level. At that point, one of the bosses has to order a new set of the product, so that before the product in stock is finished, a new set should be available in the supermarket.
In the figure, the first event is identified as 1.; the second is identified as 1.1; the third is identified as 1.1.1 . Note the writings, lines (straight or curved) and the arrows associated with the events. Assume that all the computers in the supermarket are in a network.
The first event is caused by a user in the sales department. He clicks a bottom to sell a product to a customer that came into the supermarket. This information is sent electronically to the product (inventory) database class so that the number sold should be subtracted from what is in stock. In the course of doing this subtraction the computer system will trigger another event, which is to verify (analyze) if the stock is at the reorder level or has just gone below as a result of the sales. If this is the case, then the product has to be reordered. The system will now trigger a third event, which is to inform the purchasing manager to reorder the product.
The diagram in the figure above is collaboration diagram. A collaboration diagram is one type of UML diagrams. Do not worry too much about all that for this tutorial. The aim of this tutorial is to make you understand events and what is known as triggers.
There are three basic types of database events, which are described as follows:
User Interface Event
A user interface event is that which is triggered by a user. He clicks a button on the computer screen, and information is recorded (or even changed) in the database.
Data Change Event
A data change event is that for which data crosses a preset (e.g. reorder) level, requiring that information should be sent to a personnel, or something should be done.
Business Activity Event
A business activity such as sale (subtraction of product number) can take place, requiring that the computer system does some analysis.
In some situations the distinction between the events may not be clear.
In the design of your database, instead of documenting your events in a collaboration diagram, you can document your events as triggers. A trigger is short writing of the cause of an event and the action taken.
The three events for the collaboration diagram above can be written as triggers as follows:
On (Product sale)
Then subtract Quantity From Inventory.
On(SubtractQuantity)
Then check < Reorder Level.
On (QuantityOnHand < ReorderLevel)
Then inform Purchasing Manager.
Each trigger is written in as short and as precise as possible in your own way, like programming code. There is a standard UML way of writing triggers, called OCL. You can learn that way if you want to, but you are not really obliged to learn it. You are however advised to learn it.
If you are designing a small database, what I have given you here is enough to assess and document the events. With many large databases the events become many and interwoven. For such events you need to learn other techniques or read a whole textbook in order to handle the events. What I have given you here is enough for small databases.
Well, let us stop here. I hope you appreciate all what you have read in this division. We continue in the next part, in a new division.
Chrys
Related Links
Major in Website DesignWeb Development Course
HTML Course
CSS Course
ECMAScript Course