Using the Easyui tree to illustrate the SQL GUID and the usage scenario for the self-increment column ID

Source: Internet
Author: User

The latest in the development of the tree in the Easyui, through the API can see the tree data format as follows:

Where the ID is more important, the API also said, at first I consider that the GUID than the self-increment ID more occupy some space, so the use of the self-increment ID, the test database structure is as follows:

Where the menu_id in table Tb_menu is the identity column, the step value is 1, the menu_group_id in table Tb_menugroup is also the identity column, and the step value is 1,menu_group_id as the primary foreign key relationship. I need to load all the menus in the database on the page for the user to choose, first add the test data:

INSERT  intoTb_menugroupVALUES('Production Data Maintenance','Test 1')INSERT  intoTb_menugroupVALUES('Process Line Maintenance','Test 2')INSERT  intoTb_menugroupVALUES('System Reports','Test 3')INSERT  intoTb_menuVALUES('PMC Program',1,'plan.aspx')INSERT  intoTb_menuVALUES('Process Maintenance',2,'routestep.aspx')INSERT  intoTb_menuVALUES('Bad Report',3,'defects.aspx')

The result of the return is as follows:

SELECT   from JOIN Tb_menu B  on a.menu_group_id=ORDERby1

First look at the program inside the page effect:

PS: the time before the old data has been cleared, the test data is added later, as long as the meaning can be expressed.

From the card can come out each menugroup is the parent node, and the MENU is the master node, but the tree inside each node must have a duplicate ID, the problem comes, menu_group_id and menu_id have 1,2,3,4; I added the data format of the parent node in the program as follows:

" {\ "id\": \"" "\" \ "state\": \ "closed\", \ "Iconcls\": \ "icon-hq\", \ "text\": \ " " + ds. tables[1]. rows[i]["menugroupname" "\","//  This adds the parent node

This is in a loop, so ID I use i.tostring () to achieve, but this will still be repeated, because the loop i is also starting from 0 Arabic numerals, will also be repeated with menu_id, causing the problem is clearly I this ID corresponds to the child node, But in JSON there is a same parent node, which causes the tree node to be selected when the problem (obviously no choice, you can automatically select those ID duplicate nodes), repeat the data as follows:

The id=4 data should have been functionid, but in Figure 2 it shows that menu_group_id is also 4.

As you can see from this example, GUIDs are really practical in some situations, and "unique" is the main advantage of changing the type of ID column after you reinsert the data, such as the following:

Try the GUID and identity each has its own advantages, the GUID is only a bit more than the identity space, saying that the hard disk is so cheap, do not care about this point of space, it is not as large as the amount of data to hundreds of millions of units, the advantages of the GUID is very obvious.

Using the Easyui tree to illustrate the SQL GUID and the usage scenario for the self-increment column ID

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.