Foreign keys in MySQL?

Posted by icco on Stack Overflow See other posts from Stack Overflow or by icco
Published on 2008-10-25T16:43:19Z Indexed on 2010/03/26 18:53 UTC
Read the original article Hit count: 370

Filed under:
|
|

I have been slowly learning SQL the last few weeks. I've picked up all of the relational algebra and the basics of how relational databases work. What I'm trying to do now is learn how it's implemented.

A stumbling block I've come across in this, is foreign keys in MySQL. I can't seem to find much about the other than that they exist in the InnoDB storage schema that MySQL has.

What is a simple example of foreign keys implemented in MySQL?

Here's part of a schema I wrote that doesn't seem to be working if you would rather point out my flaw than show me a working example.

CREATE TABLE `posts` (
`pID` bigint(20) NOT NULL auto_increment,
`content` text NOT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`uID` bigint(20) NOT NULL,
`wikiptr` bigint(20) default NULL,
`cID` bigint(20) NOT NULL,
PRIMARY KEY  (`pID`),
Foreign Key(`cID`) references categories,
Foreign Key(`uID`) references users
) ENGINE=InnoDB;

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql