For example to create a hierarchy of categories you use a column 'parent_id', which points to another category in the same table.
Should this be a foreign key? What would the dis/advantages be?
For example to create a hierarchy of categories you use a column 'parent_id', which points to another category in the same table.
Should this be a foreign key? What would the dis/advantages be?
Yes, you should make it a foreign key.
The benefits will be a better data model with less redundancy.
Yes. Ensures that you don't have an orphan (entry with no parent), and depending on usage, if you define a cascading delete, when a parent is deleted, all its children will also be deleted.
Disadvantage would be a slight performance hit just like any other foreign key.
Yes, you should. If you have an attribute in a relation of database that serves as the primary key of another relation in the same database you should make it a FK.
You will enjoy the advantages associated to foreign keys:
The disadvantages:
Yes you should.
Advantages (as for any foreign key):
I can't think of any real disadvantages.