在SQL中,是否可以创建一个以特定字母开头的串行主键,其次是特定数量的数字?

发布于 2025-01-26 06:37:36 字数 160 浏览 4 评论 0原文

我有许多现有数据行,似乎使用了一个唯一的标识符列,该列以字母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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

音盲 2025-02-02 06:37:36

我会将现有的行放在原状上,并继续使用不同的未来行的方案,例如一个没有字母的普通号码(铸造为字符串)。可以方便地生成序列,并且没有发生碰撞的风险。

对感知的美丽的简单性!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文