简体   繁体   中英

why we use an ID column in the table if we have a unique value

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

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.

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.

  • 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM