None of these approaches is correct. Let's say you're putting the logs like this:
numero | nome
1 | Teste 1
2 | Teste 2
2.1 | Teste
2.1.1 | Outro teste
The solution would be to create two new columns, one to be the new primary key and one to the parent registry id:
id | id_pai | numero | nome
1 | null | 1 | Teste 1
2 | null | 2 | Teste 2
3 | 2 | 1 | Teste
4 | 3 | 1 | Outro teste
Obviously, the id_pai
field would be a foreign key for the id
field of the same table. The id
field would be the primary key. The number is formed by traversing the parent, grandfather, etc record until you reach a null
and go concatenating the values of the numero
field that are found.