MySQL TABLES USERS and FLASHCARDS - how to change one depending on the other?

I am implementing a flash card application, so my FLASHCARDS table contains fields like QUESTION and RESPONSE, and my user table contains the names and personal data of my flash card application.

Here where I am confused. The FLASHCARDS table will store 100 questions and answers, classified into "groups" of cards (or decks). When USERS “use” the cards, they will also be able to decide whether the question was “EASY”, “NORMAL” or “DIFFICULT” - therefore, changing the time to the next card.

If I had only one user, that would not be a problem - I would just change the FLASHCARDS table, but I will also have 100 users. How to change the FLASHCARDS table depending on the decision of each user EASY, NORMAL or DIFFICULT and keep a record of all this for each user (I believe in the USERS table).

+4
source share
1 answer

You have a many-to-many relationship between the Flashcard entity and the User entity.

A specific "User" decides on a specific "Flash card."

A "user" may decide on zero, one or more "flash cards".

"-" , "".

" ".

, "User" "Flashcard"

:

CREATE TABLE user_flashcard
( user_id      INT UNSIGNED NOT NULL COMMENT 'fk ref user'
, flashcard_id INT UNSIGNED NOT NULL COMMENT 'fk ref flashcard'
, decision     VARCHAR(30)           COMMENT 'EASY,NORMAL,DIFFICULT'
, PRIMARY KEY (user_id,flashcard)
, CONSTRAINT FK_user_flashcard_user 
     FOREIGN KEY (user_id) REFERENCES user(id)
, CONSTRAINT FK_user_flashcard_flashcard 
     FOREIGN KEY (flashcard_id) REFERENCES flashcard(id)
)

, : , , , .

, , . , , , (id), .

, , -? (user_id,flashcard_id) .

. "" - .


, , SQL, , , SQL.

SQL Fiddle Here http://sqlfiddle.com/#!9/090ee/5

+5

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


All Articles