Jump to content


Photo

Foreign Keys


  • Please log in to reply
6 replies to this topic

#1 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 06 March 2006 - 08:45 PM

If I'm not mistaken, MySQL does not support foreign keys. Are there any alternatives to it, and if there is will you please enlighten me with tutorials and links?

Regards,
-lpxxfaintxx

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 06 March 2006 - 08:53 PM

foreign keys ARE supported in mysql. check out [a href=\"http://dev.mysql.com/doc/refman/4.1/en/ansi-diff-foreign-keys.html\" target=\"_blank\"]this page[/a] in the mysql manual for more information, but basically, you'd want to set one up in the creation of your table like this:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--]CREATE TABLE posts(
id int(11) auto_increment primary key,
user_id int(11) REFERENCES users(id) ON [span style=\'color:blue;font-weight:bold\']DELETE[/span] CASCADE
);
[!--sql2--][/div][!--sql3--]

when you use the REFERENCES keyword, you are creating a foreign key constraint which will allow you to run cascades and on update and on delete queries.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 06 March 2006 - 08:55 PM

Err... do you need access to anything to install InnoDB?

#4 fusionpixel

fusionpixel
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 06 March 2006 - 08:58 PM

[!--quoteo(post=352215:date=Mar 6 2006, 02:55 PM:name=lpxxfaintxx)--][div class=\'quotetop\']QUOTE(lpxxfaintxx @ Mar 6 2006, 02:55 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Err... what if you don't have InnoDB? And what is InnoDB?
[/quote]

How do you know if you dont have InnoDB if you dont know what InnoDB is ;) ?

[a href=\"http://dev.mysql.com/doc/refman/5.0/en/innodb.html\" target=\"_blank\"]Find more about InnoDB here[/a]

just FYI InnoDB is installed by default.
Did you know there is a manual for PHP? [a href="http://" target="_blank"]http://www.php.net[/a]
Did you know there is a manual for mySQL? [a href="http://" target="_blank"]http://www.mysql.org[/a]

#5 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 06 March 2006 - 09:02 PM

if you have MySQL installed, you have InnoDB:

Starting from MySQL 3.23.44, InnoDB features foreign key constraints.


if you want to get really technical about what the engine actually is, you can read more about it at [a href=\"http://www.innodb.com/\" target=\"_blank\"]http://www.innodb.com/[/a].

suffice to say (for all intents and purposes), it is the engine that handles your queries and constraints for you. it basically a way of storing the data. the alternative i'm most familiar with in mysql is MyISAM, and if you're running MySQL 5+, you should have FOREIGN KEY constraints in that format as well.

you're actually treading into an area that you'll probably get as much help for directly from the manual or google as you will from most users on here. ;-)
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#6 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 06 March 2006 - 09:09 PM

Hah, thanks for the extremely helpful replies guys! ;)

#7 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 06 March 2006 - 09:10 PM

[!--quoteo(post=352221:date=Mar 6 2006, 04:09 PM:name=lpxxfaintxx)--][div class=\'quotetop\']QUOTE(lpxxfaintxx @ Mar 6 2006, 04:09 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hah, thanks for the extremely helpful replies guys! ;)
[/quote]

lol... glad it was helpful ;-)... we're getting into an area where i feel like i'm spewing out all sorts of references, but i don't know that i could be much more informative than what i already wrote, so i'm glad it helped
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users