I have 2 tables:
Table A:
AID
1
2
3
4
Table B:
BID AID Status
1 1 Open
2 2 Open
3 3 Closed
4 1 Open - don't allow this row until AID 1 Status changes to closed
5 2 Open - don't allow this row until AID 2 Status changes to closed
6 3 Open - allow this row because AId 3 Status is closed
7 3 Open - don't allow this row until AID 3 Status changes to closed
How can I constraint adding another row in B table, until I change the status for AID to closed. Or should I move the Status column to A table? But even then how can I check in B table the status of A rows?
By way of demonstration: