If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > DB Design question, customer id.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-05-11, 15:23
xandout xandout is offline
Registered User
 
Join Date: Sep 2011
Posts: 2
DB Design question, customer id.

OK I am working on a program for a local company to store their client's contact info as well as the Jobs they do for each client.

in my Contact table I have the usual stuff. FName LName Email PNum STAddress City ST Zip

for jobs I need to store the following info Brand Model FormFactor PowerSupply Property1 Property2 Details and Presently in-house.

Since each client may have multiple Jobs I cannot store it in one table. I have no clue how to reference Jobs based on Client. I have tried using the phone number but that proved to be ineffective.

Is there a way that I can ensure a unique entry in "Clients" and be able to use that info when referencing "Jobs.

I am not really in need of the query code just the layout.

Any help is a[[reciated.
Reply With Quote
  #2 (permalink)  
Old 09-05-11, 17:35
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by xandout View Post
OIs there a way that I can ensure a unique entry in "Clients" and be able to use that info when referencing "Jobs.
make sure the clients table has an auto_increment primary key (call it id)

then add a client_id column to the jobs table, and link up each job to its client by placing the client's id value from the clients table into the client_id column of the jobs table for that particular job

for full marks, use the FOREIGN KEY syntax to declare the relationship explicitly

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-05-11, 18:20
xandout xandout is offline
Registered User
 
Join Date: Sep 2011
Posts: 2
Tjanks

ok that is what i had thought as well but I was tinking of doing it programmatically. I just was curious if there was a way to do it through the DataBase. Thanks for reassuring me.


Could you explain the foreign keys concept a little bit. I have tried Google but I couldn't make sense of it.
Reply With Quote
  #4 (permalink)  
Old 09-05-11, 18:48
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by xandout View Post
Could you explain the foreign keys concept a little bit.
a foreign key is a column on one table that has values which reference (i.e. come from) the primary key of another table

you can relate tables this way blindly, and control the values with application code, or better yet use the FOREIGN KEY syntax to register this relationship with the database, so that the database will ensure that no one and no application can ever insert a row with a foreign key value that doesn't exist in the referenced table
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On