title: Is chaining rows in the same table a bad pattern?
body: <p>I want to create a tree structure of categories and need to find a proper way to store it into the database. Think of the following animal tree, which pretty accurately describes how it should look like:</p>
  
  <p><a href="https://i.stack.imgur.com/BT0Bk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BT0Bk.png" alt="Animal Tree"></a></p>
  
  <p>My question now is whether chaining those entries within the same table is a good idea or not. SQLite doesn't allow me to add a FOREIGN KEY constraint to a value in the same table, so I have to make sure manually that I don't create inconsistencies. This is what I currently plan to have:</p>
  
  <pre><code>id | parent | name
  ---+--------+--------
   1 | null   | Animal
   2 | 1      | Reptile
   3 | 2      | Lizard
   4 | 1      | Mammal
   5 | 4      | Equine
   6 | 4      | Bovine
  </code></pre>
  
  <p><code>parent</code> references to an <code>id</code> in the same table, going up all the way until <code>null</code> is found, which is the root. Is this a bad pattern? And if so, what are common alternatives to put a tree structure into a relational database?</p>