Reputation: 63
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
Upvotes: 6
Views: 10651
Reputation: 4903
If your problem is creating the relationship in PHPMyAdmin, i should recommend you the following:
This way, an user can have zero or many customers and a customer will always belong to a single user.
Upvotes: 6
Reputation: 1580
You might be interested in trying MySQL Workbench It's a visual MySQL database modelling tool created and supported by Oracle/MySQL guys. Not only does it tidy away messy SQL code (but you should still understand what's going on) but seeing your database model visually is often a big help.
Upvotes: 0
Reputation: 16677
user
------
user_id
other_stuff
customer
--------
customer_id
other_stuff
user_customer
-------------
user_id
customer_id
Upvotes: 0
Reputation: 10356
What about the following
> +Users
> -id
> -email
> -full_name
>
>
> +Customers
> -id
> -user_id
> -name
> -phone
So user_id
will contain the id
of the user which this customer belongs to.
Upvotes: 1