Received: from exchhq01.usinspect.com (exchhq01.usinpect.com [208.233.45.2] (may be forged)) by hub.org (8.10.1/8.10.1) with ESMTP id e7FHw5n82352 for ; Tue, 15 Aug 2000 13:58:06 -0400 (EDT) Received: by exchhq01.usinspect.com with Internet Mail Service (5.5.2650.21) id ; Tue, 15 Aug 2000 13:57:25 -0400 Message-ID: From: "Madel, Kurt" To: pgsql-sql@postgresql.org Subject: Use a rule or a transaction Date: Tue, 15 Aug 2000 13:57:17 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain; charset="iso-8859-1" X-Archive-Number: 200008/116 Hello, I am creating a web based (using php) class registration database with three tables directly effected by the registration process: 1) class 2) student 3) module The module table has a field for every module (or class period) for every student that registers for a given year. When a student registers for a given class, the class.id for that class is placed in the respective module field. However, if class.size is equal to class.maxsize, then I don't want to allow that class.id to be inserted into the module table. If the class.size is ok, then the class.id should be added to the given module field, module.a_q1 for example AND the class.size needs to be incremented by one (further, the class.size needs to be decremented if a student drops a class). My question is, would it be better (faster) to use rules or to use a transaction. Also, if I use a transaction, it would look something like this: >begin work; >insert into module (a_q1) values (1); >update class set class.size=class.size+1 where class.id=1 and class.sizecommit work; >begin work; >insert into module (a_q2) values (3); >update class set class.size=class.size+1 where class.id=1 and class.sizecommit work; ...and so on If I did it this way, I would have to do this for 4 quarters by 6 modules (24 times). I feel like I have to do it one by one, because a student should only not get registered for classes that are full. I don't want to lump all 24 modules into one transaction and then have the student start the registration process entirely over because one class was full. Is there a faster way to do this with rules or a better way to do it otherwise. TIF, Kurt