0

I want to create a friend list for my website which is supposed to be stored in a database table, following is the table structure I think should best serve the purpose.

CREATE TABLE `sdt_friend_graph` (
  `user` INT(11) NOT NULL,
  `friend` INT(11) NOT NULL,
  `status` ENUM('requested','accepted') COLLATE utf8_unicode_ci DEFAULT NULL,
  `requested_on` DATETIME DEFAULT NULL,
  `accepted_on` DATETIME DEFAULT NULL,
  PRIMARY KEY (`user`,`friend`)
)

just want to find out if my approach is ok, or is there any better way to do this to make it more efficient, I'm open to suggestions.

Regards,

Anupam
  • 1,100
  • 2
  • 20
  • 31

1 Answers1

0

your table structure looks fine, i would just add user as an AUTO_INCREMENT field and change the name to friendid... just for semantics.

Ivan Bravo Carlos
  • 1,650
  • 3
  • 15
  • 22
  • how can I make `user` AUTO_INCREMENT it is supposed to hold the `user_id` who is generating the friend request and could be random I think, please correct me if I'm wrong or misunderstood you. Thanks for the reply. – Anupam Dec 13 '12 at 07:39
  • You are right, if you want to store existing user don't need auto increment, i got confused yes indeed you have correct. One thing i missed is the ENUM field maybe adding declined to the list would help. Cheers. – Ivan Bravo Carlos Dec 13 '12 at 07:54