SQL Inheritance: Preventing that a parent have multiple children. Auto insert and delete parent and prevent deletion of child if parent is referenced by a foreign key

If you want to model object inheritance on a SQL Database you came along some problems. First of all inheritance is not implemented, so you need a workaround. There exists three common patterns which are called Single Table Inheritance, Class Table Inheritance and Concrete Table Inheritance. If the existence of a parent row makes no sense if no child row reference it (e.g. parent is abstract) you came into some problems with standard SQL settings to guarantee this invariant. Maybe you also want that a parent row can only be specialized by exactly one child, which is only with Foreign Key not possible. In this article I will face this two problems.


User login