How to represent a data tree in SQL?

后端 未结 8 837
星月不相逢
星月不相逢 2020-12-02 06:20

I\'m writing a data tree structure that is combined from a Tree and a TreeNode. Tree will contain the root and the top level actions on the data. I\'m using a UI library to

8条回答
  •  伪装坚强ぢ
    2020-12-02 06:41

    The best way, I think indeed is to give each node an id and a parent_id, where the parent id is the id of the parent node. This has a couple of benefits

    1. When you want to update a node, you only have to rewrite the data of that node.
    2. When you want to query only a certain node, you can get exactly the information you want, thus having less overhead on the database connection
    3. A lot of programming languages have functionality to transform mysql data into XML or json, which will make it easier to open up your application using an api.

提交回复
热议问题