I am wondering if there will be consequences of the following DB schema. Say I'm writing an object. I am not sure which place properties will be stored in the database. I am thinking of creating two tables: one for storing the necessary (or general) information, and the other for storing additional information.
Table 1 - Location
- PK PlaceId
- Name
- Lat
- DLN
- etc. (all common fields)
Table 2 - PlaceData strong>
- PK DataId
- PK field name
- PK FK PlaceId
- FieldData li>
Use case
I want some visitors to be able to enter custom fields about the place. For example, a restaurant is a place that can have the following fields: HasParking, HasDriveThru, RequiresReservation, etc., But a car dealer is also a place, and these fields do not make sense for a car dealer.
I want to support any place from one table (well, the 2nd table has custom fields), because I donβt know the number of types of places that will ultimately be added to my site.
common goal
On my asp.net MVC site (C # / Razor), where I show place , it will display the attributes as an unordered list populated: SELECT * FROM PlaceData WHERE PlaceId = @0 .
Thus, I will not need to specify empty field names in the view (or do a string.IsNullOrWhitespace() check for each field). Which I would have to do if each attribute was a table column.
I assume this scenario is fairly common, but are there any better ways to do this? In particular, in terms of efficiency? What are the main disadvantages of this scheme?
source share