Use a rule or a transaction
От | Madel, Kurt |
---|---|
Тема | Use a rule or a transaction |
Дата | |
Msg-id | C6F9B91B745CD4119F1500A0C9DD60C02E348E@exchhq01.usinspect.com обсуждение исходный текст |
Ответы |
Re: Use a rule or a transaction
|
Список | pgsql-sql |
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.size<class.maxsize; >commit work; >begin work; >insert into module (a_q2) values (3); >update class set class.size=class.size+1 where class.id=1 and class.size<class.maxsize; >commit 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
В списке pgsql-sql по дате отправления: