I'm working on a project and I've come out with this doubt. I've got an IS-A relationship which looks like this:
Users
as a parent table, then Companies, Admins and Customers
as child tables. Since all of them have different attributes I've decided to create 4 tables and link them to the Users
table which will hold the login information, which is the common information between the childs.
My struggle is that I can't create a child if the parent doesn't exist obviusly, but I'd like to let the customers and companies register themselves, so the solution I've come out with is inserting a new user
, then get the max id from users
and insert a customer
. But I'm not sure if is a good approach, what happens if multiple people try to register at once?
Could I control the parent insertion from the database instead of my code? Maybe with a trigger?
That would make more sense to me, mainly because an user itself doesn't make any sense in my context, it's either a customer, an admin or a company.