如何使用alter table创建两个主键
我有具有此表单的表代理
broker
{
broker_code char(10) primary key
.
.
.
}
添加了另一个主键
,并且我已使用此表单代码 int nut null auto_increment
,并编写了此查询
ALTER TABLE broker ADD code INT NOT NULL AUTO_INCREMENT,
ADD PRIMARY KEY (code);
,但出现此错误。
multiply primary key defined.
我能做些什么?
I have table broker with this form
broker
{
broker_code char(10) primary key
.
.
.
}
and i have add to it another primary key with this form
code int nut null auto_increment
and wrote this query
ALTER TABLE broker ADD code INT NOT NULL AUTO_INCREMENT,
ADD PRIMARY KEY (code);
but it this error.
multiply primary key defined.
what can i do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不能有两个主键...但是,您可以有一个“候选”键或唯一键,它也可以防止在其他条件上重复...例如人力资源应用程序中的人员。您可以有一个内部“员工 ID”,它是主要的,但也是一个人的社会安全号码的候选密钥,该号码永远不应该重复......如果是这样,它将向 H/R 发出危险信号验证一个人是谁。
You can't have two primary keys... However, you can have a "candidate" key or Unique that also prevents duplication on other criteria... Such as a person in a human resources application. You can have an internal "employee ID" which is the primary, but also a candidate key on a person's Social Security Number which SHOULD never be duplicated... and if so, it would through up a red-flag to H/R to verify who a person is.
下面的代码有一个带有更改表的复合主键。
This code below has a composite primary key with alter table.
我不确定,因为我看不到您当前表“经纪人”的结构。
但我的猜测是您已经定义了另一个主键。
每个表只能有 1 个主键。
I'm not sure because I can't see the structure of your current table 'broker'.
But my guess is that you already defined another Primary Key.
You are only allowed to have 1 primary key per table.