need help regarding my table structure

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
greedyisg00d
Forum Commoner
Posts: 42
Joined: Thu Feb 12, 2009 2:48 am

need help regarding my table structure

Post by greedyisg00d »

I have a Employee table where its structure is EmployeeID, EmployeeName, Department and ClientsName. My problem is one employee can have many clients so my question is what is a good way on how to store multiple records to a single fields? In my case I plan to use a multiline textbox for inputting the name of the clients

Thanks
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Re: need help regarding my table structure

Post by matthijs »

You'll have to create another table for the Clients and make a reference to the Employee. So that one Employee can have more clients. If you read a few tutorials about relational database design it will become clear what I mean.
DaiLaughing
Forum Commoner
Posts: 76
Joined: Thu Jul 16, 2009 8:03 am

Re: need help regarding my table structure

Post by DaiLaughing »

As matthijs said you need another table with perhaps just two fields - employeeID and client ID. Maybe also a third table which is the clients' records if it is possible that a client can have many emplyees looking after them. Either this for where clients only have one employee:

employee --> employeesClient

or this for where they can have many:

employeeInfo --> employeesClient <-- clientInfo

You do need to read up on it though as it is perhaps the main reason that DB people are fairly well paid.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: need help regarding my table structure

Post by susrisha »

just for information.. is this called many to many linking??
DaiLaughing
Forum Commoner
Posts: 76
Joined: Thu Jul 16, 2009 8:03 am

Re: need help regarding my table structure

Post by DaiLaughing »

The second version is the way to get around the many-to-many problem, yes.
Post Reply