If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Problem about trigger on different table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-31-10, 02:31
fool1988 fool1988 is offline
Registered User
 
Join Date: Aug 2010
Posts: 1
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?
Reply With Quote
  #2 (permalink)  
Old 08-31-10, 08:16
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,574
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
Reply With Quote
  #3 (permalink)  
Old 08-31-10, 16:17
Jack Vamvas Jack Vamvas is offline
Registered User
 
Join Date: Jan 2009
Posts: 57
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
__________________
-------------
DBA DB2
SQL SERVER DBA
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On