EXPLAIN EXTENDED

How to create fast database queries

Archive for August 14th, 2013

Storing a Friendship: SQL Server Indexed Views, Part 2

with one comment

You're building a social network and want to store who is friends with whom. OK. Let's assume you want Facebook-style friends: by agreeing to be friends with someone you allow them to be friends with you too. This is called a symmetric relationship and if your social model sticks to that kind of relationship, your application should enforce its symmetry.

How shall we store friends in a database table? There are several options.

Initiator first

A table with one record per friendship and two fields for each of the friends. The person who requested the friendship is stored in the first field:

Read the rest of this entry on tech.pro ยป

Written by Quassnoi

August 14th, 2013 at 11:00 pm

Posted in SQL Server