Some advice needed...

P00HB33R

Senior Member
Joined
Jul 15, 2010
Messages
706
Reaction score
29
Location
Eloff
Is it bad practice to re-use a child table over many parent tables. Eg I have a table that contains license data like description and expiry date. This table is used as a child table for drivers, employees, vehicles and trailers.

Any advice or comments will be much appreciatted.
 
Is it bad practice to re-use a child table over many parent tables. Eg I have a table that contains license data like description and expiry date. This table is used as a child table for drivers, employees, vehicles and trailers.

Any advice or comments will be much appreciatted.

Vehicles and trailers have one kind of licence, drivers have a driver's licence, and employees? What kind of licence do they have? Perhaps a licence/registration number like doctors have?

If it's the same thing (vehicle licence for both trailer and motor vehicle), it goes in the same table.
If not, then different tables.

In this case, I would us tables: vehicle_licence, driver_licence, professional_licence.

Hope that helps.
 
Thanks man. Its mostly the same type eg. Drivers license, advanced drivers license etc. Ill probably then just split the tables to license applicable to person or vehicle. Thanks again.
 
If I understand your question correctly, the "is-a" relationship is what you are looking for: http://stackoverflow.com/questions/2862918/common-one-to-many-table-for-multiple-entities.

That would mean your child table (License) has a fk to a base parent table (LicenseeEntity). The specific parent entities would have a reference to the LicenseeEntity as a pk or one-to-one unique constraint - DriverEntity, EmployeeEntity, VehicleEntity.

Hope that makes sense.
 
Nothing wrong with a child table used by many other tables. In fact that's part of the point of a relational database. To avoid duplication of data. But you need to be careful about being too extreme about it, because it forces joins and joins in SQL mean CPU usage. There is a process in database design which should be followed to find the optimal design for your application.

An entity in one application may become a table in one application, but not in another.

It all depends on your application. In some applications only a single table is needed with a column to indicate the licence type. But if your application requires significantly different attributes for each licence type, so much so that they become different things, then separate tables might be a good idea.

I work in short term insurance and motor insurance is one of the products. We only store licence code(A1-motor cycle, B-car, B1-truck etc), licence issue date and expiry date and whether the licence is issued in the UK, EU or other country. These attributes are all on the driver table.

We only have a licence table which stores reference data for the licence codes.

I have seen some applications that take addresses to extremes. Each physical address is stored in a single table. Then a person is linked to that address in a PERSON_ADDRESS_HISTORY table. So you have a many-to-many relationship by sticking the PERSON_ADDRESS_HISTORY table between the PERSONS table and ADDRESSES table. I guess the advantage to this is that address details themselves only exist in place. This is all wonderful from a theoretical perspective, but a pain in the rear to implement in large OLTP databases, because its an extra join and when you don't really care where the person lived before, its more of a nuisance.

Of course, you come up with perfect design one day and the next day there is a better one.
 
Tahnks guys. Basicallly I have a license table, and i have a employee, driver and vehicle table using the license table to store the license type, reference and expiration date. Does that sound allright in database desifn terms?
 
as long as you would also store a license to practice medicine in the same table :)

but seriously, a driver's and a vehicle's license are similar in name, and possibly some other base fields, like expiry date. I myself might argue that the classes representing the licenses might share a common ancestor, but the data doesn't.

it might sound simple now, but can get complicated later and difficult to migrate

a vehicle's license includes things like engine number, vin, weight, etc. you might be tempted to say those belong to the vehicle entity, but that then means that if you chopshopped the vehicle and changed it's VIN, the license would still be valid.
 
Last edited:
many to many relationship between person type tables and lic tabel IF lic for all types are the same which i doubt
 
Top
Sign up to the MyBroadband newsletter
X