MySQL Forums
Forum List  »  Newbie

Re: Creating relationhips between tables
Posted by: Sean Nolan
Date: April 04, 2005 10:19AM

You need to use the InnoDB storage engine, and then create a foreign key constraint on the child table. You can create the foreign key constraint as part of the CREATE TABLE or by running an ALTER TABLE on an existing table. Here's a simple example from the docs.

CREATE TABLE parent(id INT NOT NULL, PRIMARY KEY (id)) TYPE=INNODB;
CREATE TABLE child(id INT, parent_id INT, INDEX par_ind (parent_id),
FOREIGN KEY (parent_id) REFERENCES parent(id) ON DELETE CASCADE) TYPE=INNODB;

Sean

Options: ReplyQuote


Subject
Written By
Posted
Re: Creating relationhips between tables
April 04, 2005 10:19AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.