FreiMarkt / Database

Database Scripts
1 stars 0 forks source link

ID column type #2

Open dainiusjocas opened 10 years ago

dainiusjocas commented 10 years ago

Why columns that are ID's are of type varchar? Wouldn't it be more clever to use things like UUID? For example, how are you going to generate 100 million unique strings?

CREATE TABLE member ( memberid character varying(15)[] NOT NULL,

yongzhou1314 commented 10 years ago

The length of member Id is changeable, at the first time, for example, the length of member Id can be 4, then with the increasing number of users, the length of Id can be added gradually, and I think 15 is enough for 1 billion unique strings.

dainiusjocas commented 10 years ago

First, if we follow the principle "set it and forget it", the length of the column in the DB should not be subject to change. Second, how to ensure uniqueness of this string? Of course strings of length 15 is enough to generate one billion unique strings, because it is true that 26^16 > 10^9, but how to actually produce those strings? Incorporate timestamp? Also, some random numbers? I.e. give an example of the function which creates new ID:

// java pseudocode
String[] getNextID() {
    // I would like to see this implementation.
}