views:

63

answers:

3

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

postmanid covering_pincode

What i am going to implement is, when a user enters a pincode in the textbox, the list of the postman covering that pincodes are displayed.

My doubt is, how can i enter the values in the table

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

OR

2.Storing each pincode by each seperate fields like

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 the table by pincode

+8  A: 

The rules of normalisation say: use the second one!

http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html

Mchl
+2  A: 

What you really want is a second table

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

Dan Williams
+2  A: 

I'd store each one as a separate row in your table, this would make it easier to add/edit/delete new values without having to append to or extract individual pin codes.

Use a compound key on the database table and you won't need a primary key and shouldn't have duplication.

Duncan