Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Many to Many Relationship..double or single row?

Author  Topic 

dbwilson4
Yak Posting Veteran

50 Posts

Posted - 2007-07-17 : 23:23:34
I have a friend table that specifies whether a user is a friend of another user (many-to-many) relationship.

The users friends are sorted BASED on the users preference. So there are two columns: userorder and targetorder. If you made the friendship, then userorder is the sort column while the friends sort column is targetorder.

When I select a users friends, this is the query:
SELECT * FROM (SELECT *, [userorder] as [order] FROM friends WHERE userid = @userid UNION ALL SELECT *, [targetorder] as [order] FROM friends WHERE targetid = @userid) as friends ORDER BY [order] ASC;

As you can tell, the relationship is a SINGLE row for a user.

How ever, due to complex calculations, I'm thinking it's better to just "seperate" into double rows.
So if User A becomes friend of User B, table "friends" will contain two rows instead of just 1. That way, I don't have to do the UNION ALL or complex logic to "fix" sorting issues.

Do you suggest single row or double row for a "friends table"? This table will potentionally have 100s of millions of rows (probably 500 million)

dbwilson4
Yak Posting Veteran

50 Posts

Posted - 2007-07-18 : 17:52:24
bump anyone?
Go to Top of Page
   

- Advertisement -