Broad Network


Introduction to Sybase SQL Programming for Events

Handling Sybase Events with Triggers and Procedures Using SQL – Part 1

Division 5

Forward: In this part of the series, I introduce you to Sybase SQL Programming for Events. SQL Anywhere, which is a Sybase DBMS, is what I use in the series.

By: Chrysanthus Date Published: 27 Aug 2012

Introduction

This is part 1 of my series, Handling Sybase Events with Triggers and Stored Procedures Using SQL. This series is the fifth division of my larger series, Database. You must have read all the different parts of the big series (or equivalent tutorials from elsewhere) up to this point. The previous division dealt with Implementing Database in Sybase. The title of the first part of that division is, Implementing Database in Sybase. To reach that division, just type the title and my name, Chrys in the Search Box of this page and click Search. In this part of the series, I introduce you to Sybase SQL Programming for Events. SQL Anywhere, which is a Sybase DBMS, is what I use in the series. We shall continue with the wholesale database we had in the previous division. We shall also use other tables that are not in that database.

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.

Event
An event is an action that depends on time. The Products table for the wholesale database is:

Products(ProductID, ProductName, Category, Number, CostPrice, SellingPrice)

We shall add another column to it called, ReorderLevel; to have,

Products(ProductID, ProductName, Category, Number, ReorderLevel, CostPrice, SellingPrice)

Each row in the Products table has information about one product in the company. The value of each ReorderLevel cell in a row is the minimum number of that product that should be in stock. As the company is selling, the value in the number column for each row is reducing. As soon as the value in the number column cell reaches or goes below the value in the ReorderLevel column cell of the same row, that situation is interpreted as an event. It means the CEO (or highest manager) has to be informed so that he arranges for a new set of the same product to be ordered.

Now, you can have another table in the database that the highest manager looks at everyday at say 12 O’clock. When that event occurs, the event handler code will place a new row in this table, to indicate the product concerned, the reorder level, the current level (number of products) and the timestamp. When the highest manager sees such a new row information in his table, it is up to him to take a decision.

It is possible to code such event handler with SQL. An event handler is a group of SQL statements called triggers. When the work is too much for a trigger, another type of group of SQL statements called Stored Procedure can be called to assist. Before we can code event handlers we shall have to learn more on SQL.

What is really SQL?
SQL stands for Structured Query Language. This is a computer language that a database programmer has to learn. The language consists of statements called SQL statements and each of these statement ends with a semicolon. The SQL statements we have learned so far in the big series are:

CREATE TABLE
ALTER TABLE
DROP TABLE
CREATE USER
DROP USER
GRANT
INSERT
UPDATE
DELETE
SELECT
ALTER USER

There are many more SQL statements. We shall learn some of them in this series in order to write code for event handlers.

That is it, for introduction on coding event handlers with SQL. Let us stop here and continue in the next part of the series.

Chrys

Related Courses

C++ Course
Relational Database and Sybase
Windows User Interface
Computer Programmer – A Jack of all Trade – Poem
NEXT

Comments

Become the Writer's Fan
Send the Writer a Message