开发者

Should I start user IDs from 1 or 1000 in database? Why?

开发者 https://www.devze.com 2022-12-18 17:35 出处:网络
Should I use hig开发者_如何学JAVAh numbers for user IDs in database? Are there any benefits with starting user_id from 1000 (from <9000 users project) or 10000 for more...?The advantage of starting

Should I use hig开发者_如何学JAVAh numbers for user IDs in database? Are there any benefits with starting user_id from 1000 (from <9000 users project) or 10000 for more...?


The advantage of starting user IDs from 1000 (even when you will have fewer than 9,000 IDs) is that they will all have the same number of digits, so that files, for example, suffixed with the UID will sort in numeric order automatically, even if the sorter only uses alphabetic numbering. And you don't have to pad the numbers with leading zeroes to get there.

The converse is that if you only have 1000 users, numbers starting at 1,000,000,000 would look a little silly: 1,000,000,001 then 1,000,000,002 and so on.

For many purposes, therefore, it doesn't matter which you do. A uniform number of digits has some advantages, and that is why a value other than zero or one is often used as the starting point.


not really. I would just start from 1. if you have any needs to put stuff in before one, there are no issues w/ using negative numbers, so you can just do an insert and manually specifiy the id. At my company, we start all the users at one, auto incrementing, and our global admin user is ID 0.


I know this answer comes late, but still there is something to add, imo:

1) The approach to use 1000 as a start id can be of an advantage, e.g. if you do not want to make it obvious how many users you have (in case you make the id visible somewhere in an url or sth), and therefore (or in addition)

2) it can be useful if you want to make ids harder to guess, because usually the first ids belong to admins or moderators, so if you takes any id to start (e.g. 1421), you could just add another security tweak to your db...

0

精彩评论

暂无评论...
验证码 换一张
取 消