MySQL build self-correlating table example

Source: Internet
Author: User

Note the sub_parent_id field, which enables you to associate data from the Tb_point_group_tree table as a tree data structure table.

CREATE TABLE' tb_point_group_tree ' (' cgroup_id ' )int( One) not NULL DEFAULT '0', ' group_id 'int( One) not NULLauto_increment, ' company_id 'int( One)DEFAULT NULL, ' group_name 'varchar( -)DEFAULT NULL, ' group_type_id 'int( One)DEFAULT NULLCOMMENT'Group Type: A general group, the type of electricity, the area of electricity, the production process, the key equipment', ' sub_parent_id 'int( One)DEFAULT '0'COMMENT'The Grouping Type subkey number is a self-associated gruoup_id, and if it is a parent, the value is 0',PRIMARY KEY(' group_id '),KEY' fk_reference_40 ' (' company_id ') USING BTREE,KEY' tb_sub_parent_id_fk ' (' sub_parent_id '),CONSTRAINT' Tb_point_group_tree_ibfk_1 'FOREIGN KEY(' company_id ')REFERENCES' tb_customer_info ' (' customer_id '),CONSTRAINT' TB_SUB_PARENT_ID_FK 'FOREIGN KEY(' sub_parent_id ')REFERENCES' Tb_point_group_tree ' (' group_id ') on DELETE CASCADE  on UPDATE CASCADE) ENGINE=InnoDB auto_increment= the DEFAULTCHARSET=UTF8 COMMENT='Each company can define multiple monitoring groups to facilitate management';

MySQL build self-correlating table example

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.