0

I have some issue with figured out how to store postcodes which are splitted into different areas. Example: postcodes between 97000 to 98000 are related to one area, but postcodes between 01000 to 09000 are in second area and so on. I have list all postcodes and areas which they related to but not sure how I should store it in database and later on I will have to add more areas with postcodes which are from different countries and of course notation is different.

So far what I have done I am keeping all postcode like one long string, so it looks like "97000;97001;97002...98000"(I know that is not the best way) for area one. That works fine, cause I can easily searching for one. And that could be enough but it force me to create form where I have to put that whole string and put semicolon between postcodes. Which I would like to change but no idea how(?) And that is my question.

How to bite a topic? How to store areas and postcodes related to it?

Edit: I edit it to explain what exactly I have to do.

I have Warehouse which works only for 6 areas. But those areas have multiple postcodes. So right now I have something like

Warehouses
id | name

Areas
id | warehouse_id | area_number | postcodes (as string) 

And I want to change into something like this

Warehouses
id | name

Areas
id | warehouse_id | area_number

Postcodes
id | areas_id | postcode

But that will store multiple references to the same area I am not sure if that is good. (Does not look like good idea)

noname
  • 565
  • 6
  • 23
  • 1
    Never store comma separated values in DB. It violates 1NF rule. What is the problem in storing in 2 separate columns as POSTAL_CODE | AREA. – Ankit Bajpai Aug 22 '19 at 09:46
  • I would not say is that a problem, storing it 'postal_code | area' but then I am not sure how to handle it when I have to send multiple of postcodes to database, and from different countries? – noname Aug 22 '19 at 10:38
  • I think databases are strong enough to store huge amount of data even millions records. – Ankit Bajpai Aug 22 '19 at 14:22
  • 1
    So your suggestion is to do not worry to much about that I will have 1k rows like `1 | 95000 ... 1 | 96000` ? Just want to make sure that is ok, cause I was thinking I am missing something with understanding databases. – noname Aug 22 '19 at 21:22
  • I don't think breaking it into multiple tables will help you anyway. You can keep only 1 table and proceed further. – Ankit Bajpai Aug 23 '19 at 06:02

0 Answers0