SQL to avoid Recursion

Source: Internet
Author: User


SQL avoids recursion. Today, a tangle problem is found in the development project. Modify the SQL code www.2cto.com CREATE TABLE PRO_TYPE (PRODUCTTYPEID INTEGER NOT NULL, PRODUCTTYPENAME VARCHAR2 (50) according to the parent and child classes) not null, parentid integer not null, STATUS VARCHAR2 (1) DEFAULT '1', createdate date default sysdate); comment on table PRO_TYPE IS 'product type table '; comment on column PRO_TYPE.PRODUCTTYPEID IS 'product type id'; comment on column PRO_TYPE.PRODUCTTYPENAME IS 'product type name'; COMMENT On column PRO_TYPE.PARENTID IS 'parent product type ID (0 IS the root node) '; comment on column PRO_TYPE.STATUS IS' status (0-disabled, 1-enabled )'; comment on column PRO_TYPE.CREATEDATE IS 'creation time'; alter table PRO_TYPE add constraint PK_PRO_TYPE primary key (PRODUCTTYPEID); goals to be achieved at www.2cto.com: use the parent ID or common ID to find the associated items of other tables. If the product type ID is the product parent class ID 1 0 2 0 3 1 4 2 If the structure in the database is the same, the parent-child relationship is divided, when writing SQL statements, you can select the parent class to find out the corresponding content of the subclass. How can this problem be solved. In this way: product Type ID product parent class ID 10 0 20 0 1003 10 2004 20 200401 200401 this way we use like '000000' when querying the class so that we can find all content under the sub-10 class and sub-class

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.