![](/img/trans.png)
[英]Alter primary key column that is also a foreign key of another table - Mysql
[英]Mysql alter a primary key column that has a relationship with another table
我可以将在另一个表中具有关系的主键列更改为自动递增。
这是我的代码
alter table sales_agreement modify column client_id int(11) auto_increment ;
但我得到错误:
Cannot change column 'Client_id': used in a foreign key constraint 'Relationship5' of table ' order_sheet'
编辑销售_协议表
CREATE TABLE Sales_Agreement
(
Client_id Int NOT NULL,
Client Varchar(200) NOT NULL,
PRIMARY KEY (Client_id)
) ;
表order_sheet
CREATE TABLE Sales.Order_Sheet
(
Client_id Int NOT NULL
)
;
ALTER TABLE Sales.Order_Sheet ADD PRIMARY KEY (Client_id)
;
ALTER TABLE Order_Sheet ADD CONSTRAINT Relationship5 FOREIGN KEY (Client_id) REFERENCES Sales_Agreement (Client_id)
;
尝试先删除外键,
ALTER
'Order_Sheet'
删除外键'Relationship5'
;
然后通过修改主键来更改表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.