开发者

'Integer' type or 'String' type Ids for entities in the database/application?

I am building an application in Java. My database (Cassandra) understands only byte[] as data. Thus I am free to choose among the several datatypes, for various entities IDs like the userIds or contentIds.

What should be the preferred datatype for allocating these IDs. I am looking towards sequential integeral values as userIds for the users on the application. By the database design (as planned out), a single user is going to have 4 rows in the DB. To distinguish between these four rows, I could perhaps add an extra digit to userId towards the right 开发者_运维百科most digit, that will help me in distinguishing among the 4 rows.

Does this look like a good solution? Or would String Ids be preferred ?

Any feedback is appreciated..


Definately integer ids. I've seen cases where some databases performs full-table scans with string ids. There might also be reststrictions on the length of the id field (e.g., using an encoded url for id is a bad idea). Besides id generation is best left to the database, and integers seems like the natrual choise.


Integer ids in general but...

Why does a user have 4 rows in a single table?


In my opinion everything depends on how much entities you will need to store in db. Integer type has limited set of values and if you know that you wont exceed that limit use Integer otherwise consider using Long or String type.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜