To simplify understanding: there is a table with users of one social. network. The parser complements the table with friends already existing in the database by users.

Help build a database structure, so that users leave in one table. And at the same time unload, if necessary, the relationship between the participants.

In this matter I lack the theory, the practice is polished. I would be grateful for any helpful comment.

  • one
    can for the beginning to read the literature? - Jean-Claude
  • you make up, and we will prompt correctly or not. - Jean-Claude
  • @ Jean-Claude so far only the users table and the csv-file with a list of friends (formed by a python), according to the literature: I read about social networks, and high loads (because I already collected more than 20 million lines) - Shilgen
  • 2
    Yes, it is not necessary to read the social network, but the basics of database design ... - Akina
  • @Akina is confused at this stage: for many to many, two tables of initial data and one more table of relations between them are recommended. In my case it is inappropriate. Two user tables - stupid - Shilgen

1 answer 1

Without regard to the syntax:

Create Table Users (id, name); Create table Relations ( id1 references Users(id) , id2 references Users(id) , primary key (id1, id2) , check constraint id1 < id2 ); 

Friendship is assumed to be symmetrical. For asymmetric constraint, remove.

The scheme has its advantages and disadvantages. The latter is also a lot.

  • try to implement - Shilgen