C
C#15mo 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ß15mo 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
Angius15mo ago
Many-to-many between user and user
Accord
Accord15mo 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
HeyBaldurOP15mo ago
No no, what I am asking is something more from the strategy perspective. I appreciate guys that answered but not resolved yet.
Accord
Accord15mo 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.
Want results from more Discord servers?
Add your server