Alex Misiulia
Alex Misiulia

Reputation: 1810

How to select appropriate subtype if I know just paret type ID?

I have the following trouble: https://technet.microsoft.com/en-us/library/Aa224923.howmanystoomanyfigure_01(l=en-us,v=sql.80).gif

In this image I saw model of realization supertype and subtype relationship.

Question is: if I know VehicleID and how to know exactly which kind of vehicle is it? The way I so is to write select to each table ( but it looks really ugly). Or maybe to write help table to know which type is it, but I'm not sure. Can anyone suggest a better solution?

Upvotes: 1

Views: 267

Answers (1)

Steve E.
Steve E.

Reputation: 9353

The Vehicles table has a 'type' column. This would have values in such as 'truck', 'car', 'motorcycle' and tells your code which table to query for the rest of the data.

Because the columns in the sub tables are different. I would recommend looking up the type in the Vehicles table before using a second query to get the type specific data.

Upvotes: 1

Related Questions