473,416 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Lookup FK info on MyISAM and InnoDB Table

I'm wondering if there is a way to retrieve Foreign Key declaration
information on both MyISAM and InnoDB tables.

Of course, I understand that MyISAM doesn't support Foreign Keys,
however, it does still parse FK declarations within a CREATE TABLE
statement, and moreover, it even creates an index on the column that
is the Foreign Key.

So my question is for this sample CREATE TABLE declaration:

CREATE TABLE table_name (
id INT NOT NULL AUTO_INCREMENT,
other_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (other_id) REFERENCES other_table (id))
TYPE = InnoDB --- OR --- TYPE = MyISAM
;

Can I get the Foreign Key information (meaing, the table and the
column that a FK is keyed to) from MySQL?

Doing a "DESC table_name" or "SHOW KEYS FROM table_name" indicates
that the FK column is Indexed, but doesn't really give much more
information other than that.

The only way I seem to be able to get *some* sort of FK info is if i
do a "SHOW CREATE TABLE table_name" (and even so, this only works on
InnoDB tables. For MySQL tables, it will show my foreign key
declaration as just a simple index).

Any ideas?

Thanks,
Mike
Jul 20 '05 #1
3 2691
Mike Ho wrote:
I'm wondering if there is a way to retrieve Foreign Key declaration
information on both MyISAM and InnoDB tables.


According to the docs, a table in MyISAM format does not store any info
about the reference when you declare a foreign key. It creates an index
for the referencing field, but does not record the referenced table/column.

I think the fact that it parses the foreign key declaration is just a
convenience so one's schema scripts won't cause a syntax error. But
MyISAM effectively does not support referential integrity (though that
is mentioned as a possible future enhancement in the web page that lists
long-term MySQL goals).

Regards,
Bill K.
Jul 20 '05 #2
Bill Karwin <bi**@karwin.com> wrote in message news:<cl********@enews2.newsguy.com>...
Mike Ho wrote:
I'm wondering if there is a way to retrieve Foreign Key declaration
information on both MyISAM and InnoDB tables.


According to the docs, a table in MyISAM format does not store any info
about the reference when you declare a foreign key. It creates an index
for the referencing field, but does not record the referenced table/column.


Thanks... but how about for InnoDB tables? So far the only way I can
"lookup" *any* sort of FK information is through the "SHOW CREATE
TABLE table_name" construct. Is there any other way?

Regards,
Mike
Jul 20 '05 #3
Mike Ho wrote:
how about for InnoDB tables? So far the only way I can
"lookup" *any* sort of FK information is through the "SHOW CREATE
TABLE table_name" construct. Is there any other way?


I don't know of any other way besides SHOW CREATE TABLE. I did a couple
of searches but couldn't find anything in SQL statements or in the API.

Regards,
Bill K.
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Morten Gulbrandsen | last post by:
Dear MySQL developers, Could some experienced Database developer please take a look at this ? It is supposed to be plain SQL2. How can it be coded under MySQL Especially all referential...
0
by: Morten Gulbrandsen | last post by:
Hi Programmers, after this legal statement ALTER TABLE EMPLOYEE TYPE =3D InnoDB; I get=20 Warnings: 0 =20 and still MySQL claims to have to use Type =3D MyISAM,
1
by: Sandra | last post by:
Hello, How do I convert my existing database, which I'm using MySQL ver 4 for Windows and MyISAM table type to store the data, to the new format – InnoDB, without problem ( losing data...) ...
2
by: Tom D | last post by:
I'm running MySQL 4.1 under Linux. I need to have a MyISAM table with more than 4G rows of data. I've read the manual regarding the MAX_ROWS option on tables. This table has a fixed row...
5
by: steve | last post by:
Hi, Besides transaction capability, is there anything else about innodb tables that makes it superior to myISAM? I really don’t need transactions, but for example, I need superior reliability...
3
by: siliconmike | last post by:
We have developed a site where users can post blogs. Now, each blog is stored in a separate row, in a table called blog_table. This single table would be the most active one and would grow to...
4
by: Good Man | last post by:
Hi there I have a database with about 20 or so tables, maybe a few thousand rows in each. I am starting to do more complex things with my insertions etc, and I want to start to use...
2
by: crescent_au | last post by:
I've read articles and postings about MyISAM vs InnoDB but I am still a bit unsure about which storage engine to use for my new project. I am developing a website in PHP/MySQL, which includes...
2
by: MysqlBeginner | last post by:
Is this possible to have a MyISAM table on master server and change its storage engine (to InnoDB) on slave server in a replication environment? If this is possible, what should I consider before...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.