Auto Increment varchar in MySQL

前端 未结 4 1024
眼角桃花
眼角桃花 2021-01-19 07:07

Is there a way to set primary key auto increment, type of varchar in mySql?

4条回答
  •  一向
    一向 (楼主)
    2021-01-19 07:46

    for my experience, you can make Varcar ID as auto increment but you must have logic..let say

     Dim crnum As String = "CR00001"
        Dim iTemp As Integer = 0
    
                    iTemp = CInt(crnum.Substring(4, crnum.Length - 4)) '// get only the #'s from String and Convert them to Integer.
                    iTemp += 1 '// increase the ID # + 1.
                    crnum = crnum.Substring(0, 4) & iTemp.ToString("00000") '// set the ID back with String and #'s formatted to 5 digit #.
    

    but you must do your own logic ,because after u run it for second time it will become duplicate primary key so, you must think your logic to apply your code. Anything is possible. ;)

提交回复
热议问题