Doubt about relationship between tables in mysql

5

I have the following tables:

  • Table: Customers
  • Table: Customer Interests
  • Table: User
  • In the customer interests table, I need to insert the user id and client id as foreign keys, the user id I'm going to get from a session.

    I need to know if, when creating the relationship with the respective indexes, the client id is dynamically inserted into the customer interests table as a foreign key?

        
    asked by anonymous 23.11.2015 / 14:39

    1 answer

    1

    Your modeling is not very good.

    There is no connection between the client and the user, as you will know which client is unique to the user id.

    If each client can have more than one user, then create an MxN table between user and client tables, user_user and place only the user_user in the interests table, so you will be able to consult later on which client is linked to the interest making a INNER JOIN.

    Now if each client has only one user, I do not see the reasons for two different tables, just create one in that case.

        
    23.11.2015 / 23:42