Restrict user to add "3rd" entry if capacity is 2

Hi,

I have 2 tables pen and animal table , when i am adding the animal i am assigning the pen to the animal and the pen name are coming from pen table,

i want to restrict user to add "3rd" animal if i have already set the capacity of pen to  2 animals only in pen table , any suggestions?

while adding animal user should get the alert mst or validation like " pen have capacity of 2 animals only select diff pen".

  

  Discussion posts and replies are publicly visible