Vinigas
Vinigas

Reputation: 494

SQL DB scheme modeling: Vehicle with two different type owners

I'm modeling MySQL database and started struggling.

Situation: There is vehicle table about all it's parameters. There is person table with people info. And also there is firm table with firm info. Every person and every firm can have 0..* vehicles. Every vehicle can have 0..1 owner. Vehicle owner can be only one person OR firm at once.

So I am going to query using vehicleid to get info about owner. Because there is two kind of owner in different tables, what should I do ? Add column to vehicle table which says which type owner is ?

Of course, I'm planning to create additional relation table. But I don't know how to deal with problem then foreign key can refence to two different table and only to one row.

Thanks for suggestions.

Upvotes: 0

Views: 391

Answers (1)

del cueto
del cueto

Reputation: 111

I would suggest you to have as you said a third column that would point you towards the right type of owner for each case, or you could have the person id or firm id to start with X value, such as a firm starting with F then the actual id , F0001. Then you could query with a LIKE 'F%'which would bring all values that start with F. Take it with a grain of salt tho, I still have much to learn.

Upvotes: 1

Related Questions