Hey there again,
I suggest you look up a tutorial about database normalisation. Good ones
are often hard to find.
In general, you give all tables that contain data you will be
referencing in other tables a numeric id (INT(11) UNSIGNED) as primary
key, and you use that key as the constraint.
Your table `locations` will be referenced in your table `tags` as such:
FOREIGN KEY (`location`) REFERENCES `locations`(`id`) ON UPDATE CASCADE
ON DELETE SET NULL
Search the mysql manual for those update/delete options to see what they
do and adjust them to your needs. The ones given are the ones I in most
situations.
HTH,
boro
Hiep Nguyen schreef:
Now, if I have a location table with id, name, address, phone, fax, etc...
Should I put id or name into the tag table?
If id used, then how do i look up the name, address, phone, fax, etc... when
I do a select on tag table?
Thank you for all your helps
T. Hiep
-----Original Message-----
From: Mogens Melander [mailto:[EMAIL PROTECTED]
Sent: Monday, July 02, 2007 3:45 PM
To: mysql@lists.mysql.com
Subject: Re: database structure
On Mon, July 2, 2007 21:10, Hiep Nguyen wrote:
take your advice, i looked in to JOIN and i got the idea. but i noticed
that in order to use JOIN, don't you need to have the same column name in
both tables? i just don't see it in your example here. is there
something that i'm missing?
Using the form:
select t1.field1 data1, t2.field1 data2, t3.fieldn data3
from table_a t1
left join table_b t2 on ( t1.id=t2.t1_ref )
left join table_n t3 on ( t2.id=t3.t2_ref );
You can join on allmost anything.
?? Can typecasts be used in this scenario ??
can u give a select example with JOIN on three tables above?
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]