There are 3 cases
1) Basic
Sender ---> Receiver
2) Parallel
Sender ----> Receiver1
----> ReceiverN
3) Chained
Sender ----> Primary Receiver -----> Secondary Receiver1
-----> Secondary ReceiverN
For 1) Basic and 2) Parallels, you would probably design your tables like this
Account
-Id (PK)
-UserId (FK)
-Name
-Description
-etc
Entry
-Id (PK)
-SenderAccountId (FK)
-ReceiverAccountId (FK)
Now how would you design the database to record “Chained” entries?
You can add a many to many relationship between Account(Id-PK,UserId-FK,Name,Description,…) and Entry(Id-PK) tables:
EntryAccount(EntryId & AccountId-PK,EntryAccountType)
where EntryAccountType field can have one of the following values {S=Sender,R=Receiver, P=Primary receiver,N=secoNdary receiver}.
The INSERT statements for EntryAccount table will be:
Then, to enforce some of business rules (one sender-S, one primary receiver-P and many [secondary] receivers-R/N) you can create an unique filtered index(SQL Server 2008) on EntryAccount table: IUF_EntryAccount_EntryId_EntryAccountType(key > EntryId & EntryAccountType, filter > EntryAccountType IN (‘S’,’P’)). Also, this index is good for query optimization.
But, this index is not enough because you can have “inconsistent” Entry business objects like these:
To correct this problem you need a trigger AFTER INSERT, UPDATE, DELETE on EntryAccount table:
If you don’t have SQL Server 2008 (R1/R2) you cannot create filtered index but you can rely only on trigger.
PS: I have not tested this solution.