home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1998 October A
/
Pcwk10a98.iso
/
Inprise
/
TRIAL
/
INTRBASE
/
DATA.Z
/
TRIGGERS.SQL
< prev
next >
Wrap
Text File
|
1998-03-15
|
2KB
|
78 lines
/*
THIS FILE IS FOR USE WITH THE TUTORIAL IN "GETTING STARTED",
IT IS NOT MEANT TO BE USED WITHOUT REFERRING TO THE MANUAL.
* You must change the parameters below to match your
* server name, database name , username, and password.
* This file creates triggers for the EMPLOYEE database.
*/
CONNECT "server:\dir\mydb.gdb"
USER "USERNAME" PASSWORD "password";
/*
* Create triggers for employee database
*/
CREATE GENERATOR emp_no_gen;
SET GENERATOR emp_no_gen to 145;
/* Create trigger to add unique customer number */
SET TERM !! ;
CREATE TRIGGER set_emp_no FOR employee
BEFORE INSERT AS
BEGIN
new.emp_no = gen_id(emp_no_gen, 1);
END !!
SET TERM ; !!
/* Create Generator for SET_CUST_NO trigger */
CREATE GENERATOR cust_no_gen;
SET GENERATOR cust_no_gen to 1015;
/* Create trigger to add unique customer number */
SET TERM !! ;
CREATE TRIGGER set_cust_no FOR customer
BEFORE INSERT AS
BEGIN
new.cust_no = gen_id(cust_no_gen, 1);
END !!
/* Create trigger to maintain SALARY_HISTORY table */
CREATE TRIGGER save_salary_change FOR employee
AFTER UPDATE AS
BEGIN
IF (old.salary <> new.salary) THEN
INSERT INTO salary_history
(emp_no, change_date, updater_id, old_salary, percent_change)
VALUES (
old.emp_no,
'now',
user,
old.salary,
(new.salary - old.salary) * 100 / old.salary);
END !!
CREATE TRIGGER post_new_order FOR sales
AFTER INSERT AS
BEGIN
POST_EVENT "new_order";
END !!
/*
* Get employee's projects.
*
* Parameters:
* employee number
* Returns:
* project id
*/
SET TERM ; !!