Database-wide unique-yet-simple identifiers in SQL Server

后端 未结 11 818
余生分开走
余生分开走 2020-12-12 12:50

First, I\'m aware of this question, and the suggestion (using GUID) doesn\'t apply in my situation.

I want simple UIDs so that my users can easily communicate this i

11条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 13:08

    You could use an autoincrement column to generate the unique id. Then have a computed column which takes the value of this column and prepends it with a fixed identifier that reflects the entity type, for example OR1542 and DL1542, would represent order #1542 and delivery #1542, respectively. Your prefix could be extended as much as you want and the format could be arranged to help distiguish between items with the same autoincrement value, say OR011542 and DL021542, with the prefixes being OR01 and DL02.

提交回复
热议问题