//给表添加属性
ALTER TABLE goods ADD COLUMN cid INT;
ALTER TABLE goods ADD CONSTRAINT fk_goods_category FOREIGN KEY(cid) REFERENCES category(cid);
//查看是否添加成功
SHOW CREATE TABLE goods;
MySQL中给已存在的表添加外键
最新推荐文章于 2023-02-22 18:04:26 发布
//给表添加属性
ALTER TABLE goods ADD COLUMN cid INT;
ALTER TABLE goods ADD CONSTRAINT fk_goods_category FOREIGN KEY(cid) REFERENCES category(cid);
//查看是否添加成功
SHOW CREATE TABLE goods;