[英]How to make a self to self relationship in Mysql?
I am using Heidi and I have this Table: 我正在使用Heidi,并且具有此表:
Table Category: 表类别:
The field parent_id is a reference of id. 字段parent_id是对id的引用。 This way I can do a unlimited Hierarchy of category and sub-category.
这样,我可以进行类别和子类别的无限层次结构。 How do I create this relationship in mysql Syntax?
如何在mysql语法中创建此关系?
If you mean how do you create the foreign key constraint, you just need to do something like this: 如果您是说如何创建外键约束,则只需执行以下操作:
CREATE TABLE `EXAMPLE` (
`ID` int(11) NOT NULL,
`TITLE` varchar(255) NOT NULL,
`PARENT_ID` int(11) DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `PARENT_ID` (`PARENT_ID`),
CONSTRAINT `PARENT` FOREIGN KEY (`PARENT_ID`) REFERENCES `EXAMPLE` (`ID`)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.