Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2010
    Posts
    1

    Unanswered: Problem about trigger on different table

    I having some problem to do trigger on different table..
    Please help. Thank.

    Code:
    CREATE TABLE "KHNG    "."INSTRUMENT"  (
    		  "INSTRUMENT_ID" INTEGER NOT NULL , 
    		  "INSTRUMENT_BRAND" VARCHAR(10) , 
    		  "INSTRUMENT_TYPE" VARCHAR(10) , 
    		  "INSTRUMENT_QTY" DECIMAL(5,0) NOT NULL )   
    		 IN "USERSPACE1" ; 
    
    
    -- DDL Statements for primary key on Table "KHNG    "."INSTRUMENT"
    
    ALTER TABLE "KHNG    "."INSTRUMENT" 
    	ADD CONSTRAINT "INSTRUMENT_PK" PRIMARY KEY
    		("INSTRUMENT_ID");
    Code:
    CREATE TABLE "KHNG    "."RENTED"  (
    		  "RENTED_DURATION" INTEGER NOT NULL , 
    		  "INSTRUMENT_ID" INTEGER NOT NULL , 
    		  "STAFF_ID" INTEGER NOT NULL , 
    		  "CUSTOMER_ID" INTEGER NOT NULL , 
    		  "DUEDATE" DATE NOT NULL )   
    		 IN "USERSPACE1" ; 
    
    
    -- DDL Statements for primary key on Table "KHNG    "."RENTED"
    
    ALTER TABLE "KHNG    "."RENTED" 
    	ADD CONSTRAINT "CC1283234129526" PRIMARY KEY
    		("DUEDATE");
    What i wan to do is..once the instrument_ID from rented table have been insert than it will minus 1 quantity to Instrument.instrument_qty.
    How to do the trigger?

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    What have you tried so far for your trigger?

    Also, you are going to have a problem with your "RENTED" table. You have a primary key on "DUEDATE". This will prevent any two instruments from being due on the same date.

    Andy

  3. #3
    Join Date
    Jan 2009
    Location
    United Kingdom
    Posts
    77
    If possible use a stored procedure - as possibly there is performance degrading with INSERTS. Although this will depend on your specific requirements.
    It is possible to complete what you need via a stored procedure

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •