Welcome Guest, Not a member yet? Register   Sign In
Username vs User ID
#1

[eluser]wakey[/eluser]
Hi,

I was just thinking about this and wasn't sure what the correct answer is, whether there even is a correct answer or whether it's down to personal preference.

When creating an application, for database entries created by a user, is it best to insert the entry including their username (unique and cannot be changed) or user_id (again unique and cannot be changed)?

Cheers.
#2

[eluser]JamesTaylor[/eluser]
I would do it by user_id - the user_id would be the primary key on your users table, set to auto-incrementing.

You may never want to let the user see that they have user_id, from their persective you could always use their unique username when displaying on screen but it'll be easier / cleaner for you to work with an id value for coding purposes given the experience i have (which is by no means as much as some on here!)
#3

[eluser]flaky[/eluser]
it's better if you use the user_id, since user_id will most likely be the primary key and an integer (integers are faster than char or varchar in retrieving and inserting data - assuming you are using mysql)
#4

[eluser]wakey[/eluser]
Thanks for the comments, yeah I was thinking user_id for exactly those reasons - being an int and primary key.

Thanks Smile
#5

[eluser]mohsin917[/eluser]
I use user id as primary key, but also username unique. Both are more important.
Use id in backend database relations but to use username at front its also should unique.
#6

[eluser]wakey[/eluser]
Cheers moshin917, that's what I was thinking. Appreciate the feedback on this one.
#7

[eluser]macfamous[/eluser]
[quote author="flaky" date="1267638452"]it's better if you use the user_id, since user_id will most likely be the primary key and an integer (integers are faster than char or varchar in retrieving and inserting data - assuming you are using mysql)[/quote]

ya i do with the same this .. we'll get more faster
#8

[eluser]Unknown[/eluser]
so am i, i agree with you at this point, cayoo macfamous..




Theme © iAndrew 2016 - Forum software by © MyBB