SQL:将主键从整数更改为float
我正在为非政府组织工作,我们有一个成员表,该表格用整数主键进行排序。我们想创建子成员,即成员可以是一家公司,子成员可以成为该公司的员工。
我的一个想法是将主键从整数更改为浮动,以允许诸如1.001、1.002等之类的键。
这是有意义的还是有什么更好的方法可以完成此任务?
更改主要钥匙类型的最简单方法是什么?
I am working for an NGO and we have a members table which is sorted with an integer primary key. We would like to create sub members, i.e., a member could be a company, and sub members could be employees of this company.
One idea I had would be to change the primary key from integer to float to allow keys like 1.001, 1.002 etc.
Does that make sense or is there any better way to accomplish this task?
What's the easiest way to change the primary key type?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想按公司进行排序,然后按成员进行排序,然后在顺序中使用多个列:
将float用于需要唯一的列是一个坏主意,因为float是不精确的数字。价值可能会以您不期望的方式圆形。
另请参阅:
除了重复的风险外,我同意上面的评论,不应将主要密钥与有关成员的信息的信息超载属于。为此使用属性列。如果没有别的,请考虑成员改变公司怎么办?还是会员可以同时属于多个公司?
If you want to sort by company then by member, then use multiple columns in the ORDER BY:
It's a bad idea to use FLOAT for a column that needs to be unique, because FLOAT is an inexact numeric. Values may round in ways you don't expect.
See also:
In addition to the risk of duplicates, I agree with the comments above that the primary key should not be overloaded with information about what company the member belongs to. Use an attribute column for that. If nothing else, think about what if a member changes their company? Or if members can belong to more than one company concurrently?