PDA

View Full Version : Remove duplicate data inputs



swain90
01-12-2009, 06:23 AM
I have been given a specification and the spec says i am not allowed to be able to add the same person twice. So there fore there only ever be 1 John Smith, 1 Joe Bloggs etc etc... The problem i am having is how i get this work, i can't think of a way which will allow me to do this.

CreganTur
01-12-2009, 06:29 AM
It sounds like you made employee name a primary key field. This is not good since, as you said, your company can have multiple John Smiths. Just remove the primary key restriction from that field. You'll need to come up with another PK field, however. If your company has employee ID's, then you can use that. Otherwise you could use an autonumber field (if you don't have any other options) as an employee ID just for your DB.

CreganTur
01-12-2009, 08:46 AM
[In response to PM from Op]

Again, I have to call into question the logic of your approach. I understand that you want every employee to have only 1 entry in your employees table. However, it is possible to have 2 people named John Smith in the same company. They are 2 different entities and individuals; only the name is the same.

Trying to restrict employee entry by name is a very bad idea for the reason stated above. This is why I suggest finding out if employees have a unique employee ID number. If they do not, then create one for use within your DB. Then you can refer to the employee by their unique Employee ID- this allows for the possibility of similar names without restricting you to the point that you can't have a John Smith in accounting and a John Smith in sales.

This is the entire point of a primary key- a unique identifier that can only be associated with a single record. It must be truly unique, and names are not unique.