Create mysql database for user profile

I need to create a database in which there are 3 tables, one of which is FRIENDS, the second is USERS, the third is IMAGES. I have one to many relationships between users and friends. There is one relationship between users and the picture table. I have a red question with a header structuring the database for user profiles, but this was inconvenient. They have userid as a foreign key, but I think the image id should be a foreign key in the user table.

Another question: can we have 2 foreign keys in one table, since I have a relationship with each other with a user table with pictures and a table of friends. Sorry, that is not very good in the database. I just need some help. thank

+3
source share
3 answers

You can have as many key factors as you need. It makes sense to give PICTURES a user ID if you want to associate multiple images with the user. If you want each user to have only one image, you can provide USERS with an image.

. USERS.pictureid, (, ) PICTURES , . , , driverslicencepictureid, , .., PICTURES.pictureid.

, , facebook, "" , .

, . - USERSPICTURES, . .

, .

. . , , , FRIENDS . User1Id User2Id, ( , ).

+1

- facebook, . , :

( userID, , , )

, (userID) :

"23, 345, 34, 34, 23"

. , , explode() .

, , 2 , , .

.

, :

user1 = 34 < --- , USERS
user2 = 44 < --- , USERS

+1

, . FK , FK . FKs.

(, , , "--", "" ), FK, 2 FK .

+1

Source: https://habr.com/ru/post/1777193/


All Articles