Always consider an efficient way to achieve unlimited classification in relational databases
I tried the encoding method but found that many restrictions finally gave up.
I have also tried the classification method used in general forums, but I always feel that maintenance is not very convenient.
For more advanced classificationAlgorithmLimited to your own mathematical level, you will not consider it.
Think of using XML to store structured databases to record data and results
The tree structure of XML storage has the advantages of the device and is easy to maintain. Do not use recursion.
After the XML storage structure is formatted with XSL, the parallel classification data suitable for the database is obtained directly.
Then you can directly import the data to the database.
However, a small problem is that there are more entries with multiple categories updated.
However, you can control the update under one to two categories.
In this way, the number of updated entries is relatively small.
The following is a simple example.
XML classification structure file
<? XML version = "1.0" encoding = "UTF-8" ?>
< Categorys >
< Category ID = "1" Rootid = "1" >
< Category ID = "3" Rootid = "1" >
< Category ID = "4" Rootid = "1" >
< Category ID = "7" Rootid = "1" />
</ Category >
</ Category >
< Category ID = "5" Rootid = "1" >
< Category ID = "6" Rootid = "1" >
< Category ID = "8" Rootid = "1" />
</ Category >
</ Category >
</ Category >
< Category ID = "2" Rootid = "2" />
</ Categorys >
XML classification calculation result File < Categorys >
< Category ID = "1" Rootid = "1" Parentid = "0" Depth = "0" Childcount = "6" Parentlist = "" Childlist = "3, 5" Sort = "1" />
< Category ID = "3" Rootid = "1" Parentid = "1" Depth = "1" Childcount = "2" Parentlist = "1" Childlist = "4" Sort = "2" />
< Category ID = "4" Rootid = "1" Parentid = "3" Depth = "2" Childcount = "1" Parentlist = "1, 3" Childlist = "7" Sort = "3" />
< Category ID = "7" Rootid = "1" Parentid = "4" Depth = "3" Childcount = "0" Parentlist = "1, 3, 4" Childlist = "" Sort = "4" />
< Category ID = "5" Rootid = "1" Parentid = "1" Depth = "1" Childcount = "2" Parentlist = "1" Childlist = "6" Sort = "5" />
< Category ID = "6" Rootid = "1" Parentid = "5" Depth = "2" Childcount = "1" Parentlist = "1, 5" Childlist = "8" Sort = "6" />
< Category ID = "8" Rootid = "1" Parentid = "6" Depth = "3" Childcount = "0" Parentlist = "1, 5, 6" Childlist = "" Sort = "7" />
< Category ID = "2" Rootid = "2" Parentid = "0" Depth = "0" Childcount = "0" Parentlist = "" Childlist = "" Sort = "8" />
</ Categorys >