سؤال

I'm new to the creation of triggers but I need it since I'm using a persistent storage for some IDs.

I have the table RECEIPT with a column RECEIPT_ID

and the table CONFIG_DB with columns and values:

NAME               VALUE
---------------    -----   
NEXT_RECEIPT_ID      1

and I created this trigger

CREATE TRIGGER UPDATE_RECEPCION_ID

AFTER INSERT ON RECEIPT

FOR EACH ROW 

BEGIN

UPDATE CONFIG_DB SET VALUE=VALUE+1;

END    
;

I don't know if this is OK... all I want its that after I insert a new RECEIPT_ID the VALUE in CONFIG_DB increases by 1. Thank you very much.

EDIT: I work in Mysql Workbench 5.2.40 with Mysql Server 5.5.25

هل كانت مفيدة؟

المحلول

Use following query to create trigger

delimiter |
CREATE
    TRIGGER `UPDATE_RECEPCION_ID` 
     AFTER INSERT ON `RECEIPT`
    FOR EACH ROW BEGIN
     UPDATE CONFIG_DB SET VALUE=VALUE+1 
     WHERE  NAME='NEXT_RECEIPT_ID';
    END;
    |
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top