InterBase Quick Start: Part V - More Practice with Generators and Triggers
The remainder of this section on triggers takes you through the process of creating another generator and three more triggers. There are two ways to complete this section:
- Follow the insctructions and manually enter the remaining items.
- Use the
Using the Script
If you choose to use the script do the following:
- Load the
- Execute the query.
- If you have successfully executed the
TRIGGER.SQLscript, we recommend that you back up your database.
- Advance to the page Stored Procedures.
Manually Entering the Remaining Items
We recommend that you commit your work every time after you sucessfully create a trigger or a stored procedure.
- The next trigger that you create uses the
CREATE generator cust_no_gen
SET generator cust_no_gen TO 1015
- Now execute the following
CREATE TRIGGERstatement to create the
CREATE TRIGGER set_cust_no FOR customer BEFORE INSERT AS BEGIN NEW.cust_no = gen_id ( cust_no_gen, 1 ); END
- To test this trigger, first confirm that the highest customer number is
SELECT MAX(cust_no) FROM customer
- Then insert the following row:
INSERT INTO customer (customer, contact_first, contact_last, phone_no, address_line1, address_line2, city, state_province, country, postal_code, on_hold) VALUES ('Big Rig', 'Henry', 'Erlig', '701-555-1212', '100 Big Rig Way', NULL, 'Atlanta', 'GA', 'USA', '70008', NULL)
- To confirm that the new customer number is
1016, enter the following statement:
SELECT cust_no FROM customer WHERE customer = 'Big Rig'