Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Database Query about foreign keys. HELP!!
Old 12-10-2007, 08:51 AM Database Query about foreign keys. HELP!!
Junior Talker

Posts: 4
Trades: 0
Not sure where to post this but here goes anyway. I'm currently studying database at university and i'm still quite new to it. Here is a case study:


Code:
 
A dental surgery wishes to set up a database to record the details of its patients, their appointments with dentists working at the surgery and treatments at these appointments.
A number of dentists work at the surgery. The information recorded for each dentist includes - employee code, name, address and phone number. Each patient has a - patient number, name, address and phone number to be stored. Patients make appointments. The time and date of the appointment are recorded along with a unique appointment number. Each appointment is conducted by one dentist. A patient may attend a number of appointments during their time with the the dental surgery and each dentist can conduct many appointments. One treatment may be performed at each appointment. The information recorded for a treatment includes - a treatment number and the type of treatment. Sometimes a treatment may result in the recommendation of a particular drugs. The drug code, description and recommended dose of the medication
are recorded.
The only bit that i am stuck on is the foreign keys(in bold). Do i have them within the correct entities?

ENTITY TYPES

Patient(PatientNo,Name,Address,PhoneNo)
Treatment(TreatmentNo,Type,DrugCode)
Drug(DrugCode,Description,Dose)

Appointment(AppointmentNo,Time,Date,PatientNo,EmployeeCode,TreatmentNo)
Dentist(EmployeeCode,Name,Address,PhoneNo)

Last edited by pansylea; 12-10-2007 at 08:53 AM..
pansylea is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-10-2007, 01:32 PM Re: Database Query about foreign keys. HELP!!
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Looks OK to me
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-10-2007, 01:46 PM Re: Database Query about foreign keys. HELP!!
Junior Talker

Posts: 4
Trades: 0
I wasn't sure if the PatientNo,EmployeeCode,TreatmentNo foreign keys should all be in the "Appointment" entity.
I need to know if this is definately correct because all of the other questions are based around this answer.

Thanks
pansylea is offline
Reply With Quote
View Public Profile
 
Old 12-10-2007, 07:42 PM Re: Database Query about foreign keys. HELP!!
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I wasn't sure if the PatientNo,EmployeeCode,TreatmentNo foreign keys should all be in the "Appointment" entity
Yep, because you need to pull the related data from the other tables, it certainly looks the best structure to minimise redundancy.

The only thing that seems to be missing is an appointment duration field which would possibly belong in the treatment structure if treatment types had specific durations or in the appointment if durations are variable.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-10-2007, 08:03 PM Re: Database Query about foreign keys. HELP!!
Junior Talker

Posts: 4
Trades: 0
thank you very much for advising me chrishirst.
pansylea is offline
Reply With Quote
View Public Profile
 
Old 12-11-2007, 05:59 PM Re: Database Query about foreign keys. HELP!!
Junior Talker

Posts: 4
Trades: 0
Hi, I've got another question. When i'm typing this into MYSQL how would i create a table to hold a field that only has three specific types??

I mean the field TreatmentType either has a filling,extraction or whitening

CREATE TABLE Treatment (
TreatmentNumber VARCHAR(4),
TreatmentType ....... ???????

What would i type into MYSQL to get this correct??

Thanks
pansylea is offline
Reply With Quote
View Public Profile
 
Old 12-11-2007, 10:40 PM Re: Database Query about foreign keys. HELP!!
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
I think MySQL has an enum data type? Meaning a list, like you just described.

You could use a constraint, or validation rule, to make sure people only type one of the three values you're interested in. Or, you could create a new table with an ID and a value, then set up a relationship.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Reply     « Reply to Database Query about foreign keys. HELP!!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19033 seconds with 12 queries