tags:

views:

77

answers:

3

hello i want to ask a small question here but i really don't know what is the answer of this question.

i have a accounts table which has

Username | Password

the username is a primary key so its unique

so is it necessary to put an ID column to the table ? if Yes, what is the benefit of that ?

Thanks

+2  A: 

Search by a numeric key is slightly faster (varies from one DB to another). Also, if you have a lot of references to the user table, you save some database space by having the numeric ID as the foreign key, as opposed to a string name.

Seva Alekseyev
i don't have any other related tables so there is no primary - foreign relation.i'm using MYSQL
From.ME.to.YOU
None? You don't even log what those users do?
altCognito
+1  A: 

It will make everything else easier, mainly foreign key relationships from other tables. And it allows you to change the username if you want - primary keys are not easy to change.

Otávio Décio
but my project does not allow the user to change its Username
From.ME.to.YOU
@From.Me.to.YOU: Be assured that in a sufficiently large project it is likely that you will have to change somebody's user name at some point in time. Example: If the user name is generated from their real name, and there was a typo inputting their name.
Peter Di Cecco
Or when people get married.
Andrew Medico
A: 
  • Faster in indexes
  • Consumes less disk space (and is again faster) when used as a foreign key
  • And, as mentioned a number of times, you can change the username without modifying a host of other tables.
altCognito