Can this MySQL db be improved or is it good as it is?

后端 未结 4 745
清酒与你
清酒与你 2020-12-21 19:22

In a classifieds website, you have several categories (cars, mc, houses etc). For every category chosen, a hidden div becomes visible and shows additional options the user m

4条回答
  •  失恋的感觉
    2020-12-21 20:13

    You can recognise a problem with the category tables by the use of data in the table names. The problem with having tables for each category isn't mainly that you get many tables, but that you have to change the database design if you add another category. Also, querying the database is difficult when you need to select a table based on data.

    You should have as single table for the posting properties instead of one for each category. As the properties for each category differs, you would also need a table that describes which properties are use for each category.

    Tables that describe the main objects (category, classified, poster, area, property) would get a primary key. The other tables only need foreign keys, as they are relations between objects.

    Category (CategoryId, CategoryName)
    
    Classified (ClassifiedId, PosterId, AreaId, ...)
    
    Poster (PosterId, ...)
    
    Area (AreaId, AreaName, ...)
    
    Property (PropertyId, PropertyName)
    
    CategoryProperty (CategoryId, PropertyId)
    
    ClassifiedProperty (ClassifiedId, PropertyId, Value)
    

提交回复
热议问题