· 5 years ago · Nov 03, 2020, 06:50 PM
1create database test;
2use test;
3
4drop table if exists test_self_reference;
5
6create table test_self_reference
7(
8 id int(10) unsigned NOT NULL AUTO_INCREMENT,
9 id_parent int(10) unsigned NOT NULL default 1,
10 value varchar(45) DEFAULT NULL,
11 PRIMARY KEY (id),
12 UNIQUE KEY `test_self_reference_id_UNIQUE` (id),
13 CONSTRAINT `test_self_reference_id_parent_FOREIGN` FOREIGN KEY (id_parent) REFERENCES `test_self_reference` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
14) ENGINE = InnoDB
15 AUTO_INCREMENT = 1;
16
17insert into test_self_reference (value) VALUE ('test');