Jump to content

Foreign Keys


lpxxfaintxx

Recommended Posts

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.
Link to comment
Share on other sites

[!--quoteo(post=352215:date=Mar 6 2006, 02:55 PM:name=lpxxfaintxx)--][div class=\'quotetop\']QUOTE(lpxxfaintxx @ Mar 6 2006, 02:55 PM) [snapback]352215[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Err... what if you don't have InnoDB? And what [i]is[/i] 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.
Link to comment
Share on other sites

if you have MySQL installed, you have InnoDB:
[quote]
Starting from MySQL 3.23.44, InnoDB features foreign key constraints.
[/quote]

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. ;-)
Link to comment
Share on other sites

[!--quoteo(post=352221:date=Mar 6 2006, 04:09 PM:name=lpxxfaintxx)--][div class=\'quotetop\']QUOTE(lpxxfaintxx @ Mar 6 2006, 04:09 PM) [snapback]352221[/snapback][/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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.