I would really prefer a little variation of the third way you mention:

1) table person personID primary int 11 autoincrement
 
2) table car carID primary int 11 autoincrement

3) table relation_person_car
   personID int 11
   carID int 11
   PRIMARY KEY (personID,carID)

Adolfo


> -----Original Message-----
> From: Alliax [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, December 12, 2002 8:35 PM
> To: [EMAIL PROTECTED]
> Subject: BEGINNER: in mysql, better to do 1 table for one 
> relationship, even with a one to one relation ?
> 
> 
> The way I've always done it, and I wonder if I am not doing 
> lots of things
> wrong:
> 
> i have 2 tables, one person and one address
> for a one to one relation, the way I do it:
> table person
> personID primary int 11 autoincrement
> addressID int 11
> 
> table address
> addressID primary int 11 autoincrement
> 
> if it's a one ot many relationship i do it like that:
> table person
> personID primary int 11 autoincrement
> 
> table car
> addressID primary int 11 autoincrement
> personID int 11
> 
> NOW, reading this great mailinglist, I've come to believe the 
> right way to do it that works in both relationship types : 
> table person personID primary int 11 autoincrement
> 
> table car
> carID primary int 11 autoincrement
> 
> table relation_person_car
> relation_personID primary int 11 autoincrement
> personID int 11
> carID int 11
> 
> ....
> I understand it's closer to the real way to represent 
> relations in database design, but I wonder what else can be 
> done with mySQL to simplify the work. for example, should I 
> make something special with the type of fields personID and 
> addressID in table relation_person_car ? another example, it 
> would be easier to name all the primary key fields 'id' 
> instead of '*nameOfTheTable*ID', but what would be the 
> backdraws when coding queries and server scripts ?
> 
> Any critics on my beginner way of handling relations is most welcome.
> 
> Cheers,
> Damien COLA
> 
> 
> 
> 
> 
> Cordialement,
> 
> __ Alliax         ~CV : http://LingoParadise.com/cv.php
> Un site pour Toulon   : http://www.ToulonParadise.com
> Un site pour Renaud   : http://www.rfaucilhon.com
> Un site pour Director : http://www.LingoParadise.com
> Un site pour Harmonica: http://www.LingoParadise.com/mp3
> 
> > -----Message d'origine-----
> > De : Michael T. Babcock [mailto:[EMAIL PROTECTED]] Envoyé : 
> > lundi 9 décembre 2002 15:15 À : [EMAIL PROTECTED]
> > Objet : Re: QUICK: What is the optimal way to store opening times ?
> >
> >
> > On Fri, Dec 06, 2002 at 05:54:53PM +0100, Alliax wrote:
> > > I have one question : if I go the RestTimes route, that is
> > having a row per
> > > day and so 7 row per restaurants : can I, in one SQL request,
> > know if THAT
> > > restaurant is open or close now ? I now there are NOW()
> > function in SQL and
> > > probably many others, but I am not at ease to use them since I
> > have pretty
> > > basic SQL skills.
> >
> > This should be a personal work assignment for you, but try:
> >
> > SELECT * FROM RestTimes WHERE RestID = ... AND OpenTime < now() and 
> > CloseTime > now();
> >
> > FWIW, you'll have to do a calculation in there such that 
> OpenTime is 
> > midnight today + seconds from day offset.  Its not difficult; find 
> > some calendaring
> > code for examples.
> > --
> > Michael T. Babcock
> > CTO, FibreSpeed Ltd.     (Hosting, Security, Consultation, 
> Database, etc)
> > http://www.fibrespeed.net/~mbabcock/
> >
> > 
> ---------------------------------------------------------------------
> > Before posting, please check:
> >    http://www.mysql.com/manual.php   (the manual)
> >    http://lists.mysql.com/           (the list archive)
> >
> > To request this thread, e-mail <[EMAIL PROTECTED]>
> > To unsubscribe, e-mail 
> > <[EMAIL PROTECTED]>
> > Trouble unsubscribing? Try: 
> http://lists.mysql.com/php/unsubscribe.php
> >
> 
> 
> 
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
> 
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail 
> <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
> 
> 
> 
> 


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to