MySQL Forums
Forum List  »  InnoDB

Re: add foreign key that ref's column in same table
Posted by: Don Ireland
Date: January 01, 2016 05:34PM

Thanks. They'll never be more than 1 level deep (i.e. a transaction or category can't have both a child and a parent).

It sounds like you don't see a problem with using foreign keys in this scenario. That's a relief.

Thanks for the assistance.

As to why I put the fk twice, I thought I had to -- in researching how to do this, I found the following link:

http://stackoverflow.com/a/14139144/1042053

CREATE TABLE `menus` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int(11) unsigned DEFAULT NULL,
`label` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
KEY `fk_parent_menu` (`parent_id`),
CONSTRAINT `fk_parent_menu` FOREIGN KEY (`parent_id`)
REFERENCES `menus` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
);

Don

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: add foreign key that ref's column in same table
1054
January 01, 2016 05:34PM


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.