Re: how do you find out which table fields are foreign keys?

2001-11-18 Thread Arjen G. Lentz

Hi Bennett,

- Original Message -
From: "Bennett Haselton" <[EMAIL PROTECTED]>


> Just wondering if anyone who knew the answer to this might have missed it
> before -- sorry to keep nagging but I really need to find out how, or
> whether, you can determine which fields in a table are foreign keys
> referencing another table.
>
> Is it not possible to determine, after a table is created, what fields in
> the table are foreign keys?  For a MyISAM table (where referential
> integrity is not enforced), is this information even retained?

Not yet for MyISAM, see
http://www.mysql.com/doc/A/N/ANSI_diff_Foreign_Keys.html
See also the info about InnoDB, which may do what you want.

>From a coder's point of view, I always give such columns a special name so I
know it references another table, and perhaps also also which one (and through
which column). I think that's good coding practice.
This just keeps the situation very clear to me, while coding, without having
to look up the table schema or rely on constraints.


Regards,
Arjen.

--
MySQL Training Worldwide, http://www.mysql.com/training/
   __  ___ ___   __
  /  |/  /_ __/ __/ __ \/ /Mr. Arjen G. Lentz <[EMAIL PROTECTED]>
 / /|_/ / // /\ \/ /_/ / /__   MySQL AB, Technical Writer
/_/  /_/\_, /___/\___\_\___/   Brisbane, QLD Australia
   <___/   www.mysql.com




-
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




Re: how do you find out which table fields are foreign keys?

2001-11-16 Thread Bennett Haselton

Just wondering if anyone who knew the answer to this might have missed it 
before -- sorry to keep nagging but I really need to find out how, or 
whether, you can determine which fields in a table are foreign keys 
referencing another table.

Is it not possible to determine, after a table is created, what fields in 
the table are foreign keys?  For a MyISAM table (where referential 
integrity is not enforced), is this information even retained?

 -Bennett

At 04:53 AM 11/13/2001 -0800, you wrote:
>I created the "persons" and "shirts" tables as described in the MySQL 
>tutorial:
>
>http://www.mysql.com/doc/e/x/example-Foreign_keys.html
>
>such that the "owner" field in shirts is a foreign key referencing the 
>"persons" table.  However, "describe shirts" does not indicate that the 
>field is a foreign key: (may have to widen mail viewer window to view the 
>following table)
>
>mysql> describe shirts;
>+---+-+--+-+-++
>| Field | Type| Null | Key | 
>Default | Extra  |
>+---+-+--+-+-++
>| id| smallint(5) unsigned|  | PRI | 
>NULL| auto_increment |
>| style | enum('t-shirt','polo','dress')  |  | | 
>t-shirt ||
>| color | enum('red','blue','orange','white','black') |  | | 
>red ||
>| owner | smallint(5) unsigned|  | | 
>0   ||
>+---+-+--+-+-++
>4 rows in set (0.00 sec)
>
>How do I find out which fields are foreign keys?
>
>For that matter, in a MyISAM table, what difference does it make whether 
>you specify that a given field is a foreign key referencing another table 
>-- as opposed to just an integer field with the same data type as the key 
>field of another table?  Since referential integrity is not enforced with 
>MyISAM tables, does it not make any difference whether I tell it that a 
>field is a foreign key?  Is that information discarded entirely?  (Which 
>would explain why "describe" doesn't show it.)
>
>The only reason I wanted to know whether a given field was a foreign key, 
>was because I'm hammering together my own Web-based interface to MySQL 
>tables, and I was hoping that when the table contents are rendered in an 
>HTML table and a given field is a foreign key, I can have its value 
>hyperlinked to the appropriate row in the table that it references.
>
> -Bennett
>
>[EMAIL PROTECTED] http://www.peacefire.org
>(425) 649 9024
>
>
>-
>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
>


[EMAIL PROTECTED] http://www.peacefire.org
(425) 649 9024


-
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