CREATE TABLE `TAB001_TYPE` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` TEXT NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `TAB002_FIELD` (
`id` INT NOT NULL AUTO_INCREMENT,
`t001_id` INT NOT NULL,
`field_name` TEXT NOT NULL,
`field_note` TEXT NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `TAB004_DOC_VALUE` (
`id` INT NOT NULL AUTO_INCREMENT,
`t003_id` INT NOT NULL,
`t002_id` INT NOT NULL,
`value` varchar NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `TAB003_DOCS` (
`id` INT NOT NULL AUTO_INCREMENT,
`t001_id` INT NOT NULL,
`doc_name` TEXT NOT NULL,
`doc_num` INT NOT NULL,
PRIMARY KEY (`id`)
);
ALTER TABLE `TAB002_FIELD` ADD CONSTRAINT `TAB002_FIELD_fk0` FOREIGN KEY (`t001_id`) REFERENCES `TAB001_TYPE`(`id`);
ALTER TABLE `TAB004_DOC_VALUE` ADD CONSTRAINT `TAB004_DOC_VALUE_fk0` FOREIGN KEY (`t003_id`) REFERENCES `TAB003_DOCS`(`id`);
ALTER TABLE `TAB004_DOC_VALUE` ADD CONSTRAINT `TAB004_DOC_VALUE_fk1` FOREIGN KEY (`t002_id`) REFERENCES `TAB002_FIELD`(`id`);
ALTER TABLE `TAB003_DOCS` ADD CONSTRAINT `TAB003_DOCS_fk0` FOREIGN KEY (`t001_id`) REFERENCES `TAB001_TYPE`(`id`);