C
C#10mo ago
HeyBaldur

❔ Contacts DB Strategy

Hey guys! I have a question, maybe someone can give a nice shot with this problem. I have DB where there are multiple users [dbo].[Users], however every user might have another user as a contact and vise-versa. For example: User1 wants to be a contact of User2, but at the moment that we save that in SQL, (in our DB) we will have Id, U1, U2, hypothetically speaking, it will be like Id: 1, User1: "ABC", User2: "DEF" But at the moment to User2 want to query his contacts, the query will must be something like: SELECT 1 FROM Contacts WHERE (User1 = @SenderId AND User2 = @RecipientId) OR (User1 = @RecipientId AND User2 = @SenderId) And this is an actual problem, does anyone knows a better approach in such scenario how it can be optimal to do this?
5 Replies
Florian Voß
Florian Voß10mo ago
User: Id (PK) Contact: Id (PK) UserId (FK) ContactId(FK) is what I'm thinking of one to many between user and contact
Angius
Angius10mo ago
Many-to-many between user and user
Accord
Accord10mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
HeyBaldur
HeyBaldur10mo ago
No no, what I am asking is something more from the strategy perspective. I appreciate guys that answered but not resolved yet.
Accord
Accord9mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.