Thursday 18 November 2010 9:11:37 am
Let’s start creating a simple database table. In this tutorial we will create a table to store the friendship relations between users. Our database will have only three columns :
Every time a user 1 makes a friendship request to a user 2, we store this information in the database. A status 0 means that the request is pending, 1 means that the request was accepted.
Code :
CREATE TABLE tutorial_friendship ( user1_id int(11) NOT NULL, user2_id int(11) NOT NULL, status int(11) NOT NULL, PRIMARY KEY (user1_id, user2_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Here's the PostgreSQL version :
CREATE TABLE tutorial_friendship ( user1_id integer DEFAULT 0 NOT NULL, user2_id integer DEFAULT 0 NOT NULL, status integer DEFAULT 0 NOT NULL, PRIMARY KEY (user1_id,user2_id) );