Topic
1 reply Latest Post - ‏2012-09-19T11:37:09Z by rmantyla
SystemAdmin
SystemAdmin
115 Posts
ACCEPTED ANSWER

Pinned topic Trigger on Insert

‏2012-07-21T08:34:22Z |
Hi,

I'd like to create trigger on a table.

I have table named CUSTOMER having columns

C_ID
C_NAME
C_SURNAME
C_MONUM
C_HONUM
C_CITY
C_COUNTRY

My aim is to create trigger on table so that

if CO_HONUM is 994422114330 in row, I'd like that record to be not inserted in a table.

Thanks,

Albina
Updated on 2012-09-19T11:37:09Z at 2012-09-19T11:37:09Z by rmantyla
  • rmantyla
    rmantyla
    4 Posts
    ACCEPTED ANSWER

    Re: Trigger on Insert

    ‏2012-09-19T11:37:09Z  in response to SystemAdmin
    Hi,

    here is an example.

    CREATE TABLE C_INFORMATION (
    C_ID VARCHAR,
    C_NAME VARCHAR,
    C_SURNAME VARCHAR,
    C_MONUM VARCHAR,
    C_HONUM VARCHAR,
    C_CITY VARCHAR,
    C_COUNTRY VARCHAR
    );
    COMMIT WORK;

    "CREATE TRIGGER TRIGGER_CHECK_C_HONUM ON C_INFORMATION
    BEFORE INSERT
    REFERENCING NEW C_HONUM AS NEW_C_HONUM
    BEGIN
    IF NEW_C_HONUM = '994422114330' THEN
    RETURN SQLERROR 'Error in TRIGGER_CHECK_C_HONUM ';
    END IF
    END";
    COMMIT WORK;

    Now
    insert into C_INFORMATION values (2, 'John', 'Smith', '1', '994422114330', 'Los Angeles', 'USA');
    should return
    SOLID Procedure Error 23518: User error: Error in TRIGGER_CHECK_C_HONUM

    Regards,
    Risto