Search code examples
mysqldatabasedatabase-designdatabase-normalization

DB schema to store different types of places in a city


I have to store all places of city in database. As places are different like schools, colleges, university, hospital, hostel, hotel, shop, fast foods, bus station, banks etc

I cannot store them in one table because they have different attributes and also categories are unknown, and catagories may be added later at run time. So we cannot fix attributes.

How to solve this problem? please help.


Solution

  • Your request is pretty vague, and @Jamie is absolutely right in his pessimism. You should find yourself a consultant to help you.

    That said...

    You can make separate tables for each entity (school, college, etc). Note that they all share some basic characteristics (they have a 'name', an 'address', etc). You can put those in a different table, which should simplify things, so:

     place (id, name, address, city, state, zip)
     school (place_id, principals_name)
     college (place_id, is_accredited)
    

    This makes it easier to add attributes to any given place (as you won't have one large table to ALTER). Note that I said easier, not easy.

    Many people will add generic columns like 'data1', 'data2', but I've always found that to be confusing and difficult to maintain.

    Please go find a consultant... Free advice is worth exactly what you pay for it...