on 2013 Nov 18 12:36 AM
A table: TRANS_No part_id quantity unit_price ar_amt customer_id
TR001 A001 10 30 300 Customer001 TR001 A004 20 40 800 customer001 B tabel: customer_id limit customer001 900 insert A if sum(a.ar_amt)>b.limit --Are not allowed to insert data sum(a.ar_amt)<b.limit --can insertdata)
How to use the trigger judge whether the insert data of A total is greater than the table B, if the limit is greater than B is not allowed to insert So what do I need the triggers. If he is greater than the number that I will let him save, the judgment of statements or constraint statement I should how to write?
Request clarification before answering.
Thanks for jason.hinsperger help me : The answer is:
Declare tot integer; Declare lim integer; Select sum(amt) into tot where customer_id = newrow.customer_id; Select limit into lim where customer_id = newrow.customer_id; If tot > lim then Raiserror 30002 ‘You cannot go over your limit’; endif
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
76 | |
30 | |
8 | |
8 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.