Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advise on creating relationship in mysql with phpmyadmin

I was wondering if anyone could help me with this as I am novice and very confused

I want to able to assign customer to user (1:M relationship) but I cant figure how to do this in mysql. What I would like to do is in the customer table add the multiple id's of the user and then create a table where you can assign a new customer to a certain user or search how many customer a particular user has etc...

I have been looking at creating relationship but I keep getting error in phpmyadmin

Can anyone advise how to do this properly in the db please

Thanks for all your help

like image 330
user1200819 Avatar asked Oct 10 '12 21:10

user1200819


1 Answers

If your problem is creating the relationship in PHPMyAdmin, i should recommend you the following:

  • Create the user table with the user_id as PK.
  • Create the customer table adding the user_id column and defining it as an INDEX.
  • Go to Customer table structure, and click on "View Relations".
  • On the user_id field, choose the User_table.user_id.

This way, an user can have zero or many customers and a customer will always belong to a single user.

like image 96
Mateus Schneiders Avatar answered Sep 26 '22 02:09

Mateus Schneiders