Solved

MySQL foreign key problems

Posted on 2004-04-30
4
2,814 Views
Last Modified: 2008-03-03
is it true that mysql does not support foreign keys? i am using the mysql server and mysql control center currently and it works perfectly. and today i knew that it does not support foreign key, how can i link a primary key to another table? if i cant do so, does this mean i have to update 2 tables at once or have to create more tables?
0
Comment
Question by:otyew
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Expert Comment

by:culshaja
ID: 10960846
This is from the manual:

'In MySQL Server 3.23.44 and up, the InnoDB storage engine supports checking of foreign key constraints, including CASCADE, ON DELETE, and ON UPDATE. See section 16.7.4 FOREIGN KEY Constraints.

For storage engines other than InnoDB, MySQL Server parses the FOREIGN KEY syntax in CREATE TABLE statements, but does not use or store it. In the future, the implementation will be extended to store this information in the table specification file so that it may be retrieved by mysqldump and ODBC. At a later stage, foreign key constraints will be implemented for MyISAM tables as well. '

I think version 5 will support them fully. Until then if you are not using InnoDB you will have to do it manually.

James :-)
0
 
LVL 14

Accepted Solution

by:
cracky earned 30 total points
ID: 10961254
culshaja is correct, MySQL actually has quite a good Foreign Key referential integrity system in the InnoDB database storage engine.

If you need a really good tutorial on how to set this up, see:

http://www.databasejournal.com/features/mysql/article.php/2248101
0
 

Author Comment

by:otyew
ID: 10967619
dear cracky,

i have heard of innodb and even recommeded to use it too but i do not know what it is. issit already available in the mysql? or i have to download it? i am fairly new to mysql
0
 
LVL 14

Expert Comment

by:cracky
ID: 10967659
InnoDB is already active in current MySQL distributions.

If you are new to MySQL, I would recommend installing phpMyAdmin on your webserver to make your life a lot easier:

http://www.phpmyadmin.net/

If you follow the tutorials above, you will be able to get started pretty quickly. I use InnoDB in my applications and it works great.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question