Confuses the design of the table. How to store multiple data

I have a table for storing the coverage area of ​​a postman. It has two fields

postmanid covering_pincode

What I'm going to implement is when the user enters a pincode in a text box, a list of the postman that covers these pincodes is displayed.

I doubt how I can enter the values ​​in the table

1. Multiple pincodes stored in single row like  
postmanid->1, covering_pincode-> 626123, 626124, 626432, 654564

OR

2. Saving each pincode with each separate field, for example

postmanid->1, covering_pincode->626123,
postmanid->1, covering_pincode->626124,
postmanid->1, covering_pincode->626432, 
postmanid->1, covering_pincode->654564

Please help which one is best for searching a table using pincode

+3
source share
3 answers
+9

, ,

covering_pincodeid- > 1, postmanid- > 1, convering_pincode- > 626123 covering_pincodeid- > 2, postmanid- > 1, convering_pincode- > 626124 covering_pincodeid- > 3, postmanid- > 1, convering_pincode- > 626125

+2

I would save each of them in a separate row in your table, this would simplify adding / editing / deleting new values ​​without the need to add or remove separate pin codes.

Use the composite key in the database table, and you will not need the primary key and should not have duplication.

+2
source

Source: https://habr.com/ru/post/1757702/


All Articles