Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2841
  • Last Modified:

MySQL foreign key problems

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
otyew
Asked:
otyew
  • 2
1 Solution
 
culshajaCommented:
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
 
crackyCommented:
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
 
otyewAuthor Commented:
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
 
crackyCommented:
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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now