How to automatically generate unique id in SQL like UID12345678?

后端 未结 5 2156
情深已故
情深已故 2020-11-30 04:42

I want to automatically generate unique id with per-defined code attach to it.

ex:

UID12345678
CUSID5000

I tried uniqueiden

5条回答
  •  醉梦人生
    2020-11-30 04:55

    If you want to add the id manually you can use,

    PadLeft() or String.Format() method.

    string id;
    char x='0';
    id=id.PadLeft(6, x);
    //Six character string id with left 0s e.g 000012
    
    int id;
    id=String.Format("{0:000000}",id);
    //Integer length of 6 with the id. e.g 000012
    

    Then you can append this with UID.

提交回复
热议问题