MySQL - how to use VARCHAR as AUTO INCREMENT Primary Key

后端 未结 3 1733
日久生厌
日久生厌 2020-12-16 22:36

I am using a VARCHAR as my primary key. I want to auto increment it (base 62, lower/upper case, numbers), However, the below code fails (for obvious reasons):



        
3条回答
  •  星月不相逢
    2020-12-16 23:05

    example of a solution to your problem:

    create a file with a unique number and then increment with a function.

    the filename can be the prefix and the file binary content represent a number.

    when you need a new id to the reg invoque the function

    Example

        String generateID(string A_PREFIX){
            int id_value = parsetoInt(readFile(A_PREFIX).getLine())
            int return_id_value = id_value++
            return return_id_value
        }
    

    where "A_PREFIX-" is the file name wich you use to generate the id for the field.

提交回复
热议问题