Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 550
  • Last Modified:

Trigger insert sequence from defined set of values

I am not quite sure how to describe it but I have an application where end users submit accounts to be worked and they all go in a table. I am in need of assigning these accounts to a group of ten other users for example. These ten users have their own personal user id's.

Thus when the account is inserted into the table a trigger needs to insert a specific user id in the "Assigned" column and do so in a sequence to ensure an equal number of accounts per person. Just not sure how to design this.

Thanks in advance.
0
mjfigur
Asked:
mjfigur
1 Solution
 
slightwv (䄆 Netminder) Commented:
Round robin? So every 10th record is assigned to the same person?

Try the MOD operator against the sequence.

Not 100% accurate since sequences are not gapless but something like setting assigned to: Mod(sequence.nextval,10)
0
 
Franck PachotCommented:
Hi,

How do you need to manage concurrency and rollbacks ?
 - what if the transaction that inserts do not commit ? The user assignation is rolled back and the user should available for another assignation.
 - what if several concurrent inserts ? Each insert will not see the non-committed assignation, and finally when they all commit they will assign too much to a user.

Sequences (or random number) will be the most efficient, by result may not be balanced over users (gaps, rollbacks)

Keeping the number of assignation for each user in a table will solve that, but you will have concurrency issues (locks) when inserting.

Maybe you can change the design: instead of assigning at insert time, you should assign it when you query what the user has to work on: just pick the next 10 accounts from the queue (queue being the non-assigned accounts).

Regards,
Franck.
0
 
mjfigurAuthor Commented:
Thank you that is such a great idea. Will have it pull dynamically assigning them when they are requested will allow for my fluidity especially when one of the users may be out of the office on a given day or week.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now