So I have a table T with some attributes say A and B. A condition on the table is that every value of B must have atleast 'n' rows in the table (with different values of A).
I want to ensure that if a record is deleted from the table T, it can only happen if the atleast 'n' condition holds for the remaining records. That is, if there are exactly 5 rows that have the attribute B with value = 1, then a row with B=1 cannot be deleted.
I'm wondering how I can write a trigger in SQL to handle this, or if a trigger is even the best way of doing this. Any suggestions?