在SQL中,是否可以创建一个以特定字母开头的串行主键,其次是特定数量的数字?
我有许多现有数据行,似乎使用了一个唯一的标识符列,该列以字母K开头,其后是8或9个随机数。我想将此列用作表中的主要键。对于将来在表中添加的所有添加,我想自动生成遵循与现有数据相同格式的唯一PK。有没有办法在SQL代码中实现此目标,还是我需要创建一个生成唯一PK的精细(对于我的初学者级别)python函数?
I have many lines of existing data which seems to use a unique identifier column that begins with the letter K and is followed by 8 or 9 random numbers. I would like to use this column as the primary key in a table. For all future additions to the table I'd like to automatically generate a unique PK that follows the same format as the existing data. Is there a way to achieve this within SQL code, or would I need to create an elaborate (for my beginner level) Python function that generates the unique PK?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会将现有的行放在原状上,并继续使用不同的未来行的方案,例如一个没有字母的普通号码(铸造为字符串)。可以方便地生成序列,并且没有发生碰撞的风险。
对感知的美丽的简单性!
I would leave the existing rows as they are and continue with a different scheme for future rows, for example a plain number without letter (cast to a string). That can be generated with a sequence conveniently, and there is no risk of collisions.
Simplicity over perceived beauty!