database – is the zip code a unique ID in Brazil?


I own the official base of zip codes in Brazil, the e-DNE, sold by mail.

I need to create a new database from it, and I would like to know if I can use the zip code as the unique identifier of my DB.

As there are locations that use the same zip code for multiple addresses, I would like to know how to uniquely identify these locations.


Let's go back to the theory of primary keys a little, we should do some analysis: Basic rules for primary keys:

  1. There CANNOT be two occurrences of the same entity with the same content in the Primary Key
  2. The primary key cannot be composed of an optional attribute, that is, an attribute that accepts null.
  3. The identifying attributes must be the minimum set that can identify each instance of an entity.
  4. External keys must not be used. (Attributes over which you have no control. Ex: CPF, CNPJ)
  5. Each identifier attribute of the key must have a reduced size It must not contain volatile information.

Let's start with number 4, where zip code is a foreign key, that is, if a number is included or there is any modification, how would you act in cases like this? Remembering that recently in the city of São Paulo there was a change in the telephone number. Changes like these to a PK (primary key) would cause a lot of problems. The idea of ​​following the normalizations is to guarantee the stability of your database with the ACID (Atomicity, Consistency, Isolation and Durability).

You could even facilitate the search using the zip code as INDEX, it would help, however, in this case it is best to keep the PK with an auto-increment ID.

Scroll to Top